Class: MoxiworksPlatform::Company
- Defined in:
- lib/moxiworks_platform/company.rb
Overview
Moxi Works Platform Company
Instance Attribute Summary collapse
-
#moxi_works_company_id ⇒ String
moxi_works_company_id is the Moxi Works Platform ID of the company.
-
#name ⇒ String
the human readable name of this Company.
-
#partners ⇒ Array
Partner data associated with this Company.
Attributes inherited from Resource
Class Method Summary collapse
-
.find(opts = {}) ⇒ MoxiworksPlatform::Company
Find a Company by ID in Moxi Works Platform.
-
.search(opts = {}) ⇒ Array
Show all my Companies in Moxi Works Platform.
Methods inherited from Resource
accept_header, attr_accessor, attributes, #attributes, auth_header, check_for_error_in_response, content_type_header, #float_attrs, headers, #init_attrs_from_hash, #initialize, #int_attrs, #method_missing, #numeric_attrs, #numeric_value_for, send_request, #to_hash, underscore, underscore_array, underscore_attribute_names, underscore_hash, user_agent_header
Constructor Details
This class inherits a constructor from MoxiworksPlatform::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MoxiworksPlatform::Resource
Instance Attribute Details
#moxi_works_company_id ⇒ String
moxi_works_company_id is the Moxi Works Platform ID of the company
9 10 11 |
# File 'lib/moxiworks_platform/company.rb', line 9 def moxi_works_company_id @moxi_works_company_id end |
#name ⇒ String
the human readable name of this Company
15 16 17 |
# File 'lib/moxiworks_platform/company.rb', line 15 def name @name end |
#partners ⇒ Array
Partner data associated with this Company
21 22 23 |
# File 'lib/moxiworks_platform/company.rb', line 21 def partners @partners end |
Class Method Details
.find(opts = {}) ⇒ MoxiworksPlatform::Company
Find a Company by ID in Moxi Works Platform
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/moxiworks_platform/company.rb', line 32 def self.find(opts={}) raise ::MoxiworksPlatform::Exception::ArgumentError, 'arguments must be passed as named parameters' unless opts.is_a? Hash required_opts = [:moxi_works_company_id] required_opts.each do |opt| raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if opts[opt].nil? or opts[opt].to_s.empty? end url = "#{MoxiworksPlatform::Config.url}/api/companies/#{opts[:moxi_works_company_id]}" self.send_request(:get, opts, url) end |
.search(opts = {}) ⇒ Array
Show all my Companies in Moxi Works Platform
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/moxiworks_platform/company.rb', line 55 def self.search(opts={}) raise ::MoxiworksPlatform::Exception::ArgumentError, 'arguments must be passed as named parameters' unless opts.is_a? Hash url ||= "#{MoxiworksPlatform::Config.url}/api/companies" required_opts = [] required_opts.each do |opt| raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if opts[opt].nil? or opts[opt].to_s.empty? end results = MoxiResponseArray.new() RestClient::Request.execute(method: :get, url: url, payload: opts, headers: self.headers) do |response| puts response if MoxiworksPlatform::Config.debug results.headers = response.headers self.check_for_error_in_response(response) json = JSON.parse(response) results.page_number = 1 results.total_pages = 1 json.each do |r| results << MoxiworksPlatform::Company.new(r) unless r.nil? or r.empty? end end results end |