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.
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
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 |
Class Method Details
.find(opts = {}) ⇒ MoxiworksPlatform::Company
Find a Company by ID in Moxi Works Platform
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/moxiworks_platform/company.rb', line 26 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
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/moxiworks_platform/company.rb', line 49 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 = [] RestClient::Request.execute(method: :get, url: url, payload: opts, headers: self.headers) do |response| puts response if MoxiworksPlatform::Config.debug self.check_for_error_in_response(response) json = JSON.parse(response) json.each do |r| results << MoxiworksPlatform::Company.new(r) unless r.nil? or r.empty? end end results end |