Class: MoxiworksPlatform::Company

Inherits:
Resource
  • Object
show all
Defined in:
lib/moxiworks_platform/company.rb

Overview

Moxi Works Platform Company

Instance Attribute Summary collapse

Class Method Summary collapse

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_idString

moxi_works_company_id is the Moxi Works Platform ID of the company

Returns:

  • (String)

    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

#nameString

the human readable name of this Company

Returns:

  • (String)

    the human readable name of the 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

Parameters:

  • opts (Hash) (defaults to: {})

    named parameter Hash

Options Hash (opts):

  • :moxi_works_company_id (String)

    REQUIRED The Moxi Works Company ID

Returns:

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



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

Examples:

results = MoxiworksPlatform::Companies.search

Returns:

  • (Array)

    containing MoxiworksPlatform::Companies objects

Raises:

  • ::MoxiworksPlatform::Exception::ArgumentError if required named parameters aren’t included



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