Class: MoxiworksPlatform::Office

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

Overview

Moxi Works Platform Office

Instance Attribute Summary collapse

Attributes inherited from Resource

#headers

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, #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

#addressString

Returns the office’s address, street and number.

Returns:

  • (String)

    the office’s address, street and number



28
29
30
# File 'lib/moxiworks_platform/office.rb', line 28

def address
  @address
end

#address2String

Returns address cont. (ex. suite number).

Returns:

  • (String)

    address cont. (ex. suite number)



33
34
35
# File 'lib/moxiworks_platform/office.rb', line 33

def address2
  @address2
end

#alt_phoneString

Returns the office’s alternate phone number.

Returns:

  • (String)

    the office’s alternate phone number



58
59
60
# File 'lib/moxiworks_platform/office.rb', line 58

def alt_phone
  @alt_phone
end

#cityString

Returns the office’s address, city.

Returns:

  • (String)

    the office’s address, city



38
39
40
# File 'lib/moxiworks_platform/office.rb', line 38

def city
  @city
end

#common_nameString

Returns the commonly used name of the office.

Returns:

  • (String)

    the commonly used name of the office



23
24
25
# File 'lib/moxiworks_platform/office.rb', line 23

def common_name
  @common_name
end

#countyString

Returns the office’s address, county.

Returns:

  • (String)

    the office’s address, county



43
44
45
# File 'lib/moxiworks_platform/office.rb', line 43

def county
  @county
end

#emailString

Returns the office’s email address.

Returns:

  • (String)

    the office’s email address



63
64
65
# File 'lib/moxiworks_platform/office.rb', line 63

def email
  @email
end

#facebookString

Returns the office’s facebook page URL.

Returns:

  • (String)

    the office’s facebook page URL



68
69
70
# File 'lib/moxiworks_platform/office.rb', line 68

def facebook
  @facebook
end

#google_plusString

Returns the office’s google_plus account.

Returns:

  • (String)

    the office’s google_plus account



73
74
75
# File 'lib/moxiworks_platform/office.rb', line 73

def google_plus
  @google_plus
end

#image_urlString

Returns a URL to an image of the office.

Returns:

  • (String)

    a URL to an image of the office.



13
14
15
# File 'lib/moxiworks_platform/office.rb', line 13

def image_url
  @image_url
end

#moxi_works_office_idString

Returns the UUID of the office.

Returns:

  • (String)

    the UUID of the office



8
9
10
# File 'lib/moxiworks_platform/office.rb', line 8

def moxi_works_office_id
  @moxi_works_office_id
end

#nameString

Returns the legal name of the office.

Returns:

  • (String)

    the legal name of the office



18
19
20
# File 'lib/moxiworks_platform/office.rb', line 18

def name
  @name
end

#office_websiteString

Returns url of the office’s website.

Returns:

  • (String)

    url of the office’s website



93
94
95
# File 'lib/moxiworks_platform/office.rb', line 93

def office_website
  @office_website
end

#phoneString

Returns the office’s primary phone number.

Returns:

  • (String)

    the office’s primary phone number



78
79
80
# File 'lib/moxiworks_platform/office.rb', line 78

def phone
  @phone
end

#regionString

Returns office’s region.

Returns:

  • (String)

    office’s region



98
99
100
# File 'lib/moxiworks_platform/office.rb', line 98

def region
  @region
end

#stateString

Returns the office’s address, state.

Returns:

  • (String)

    the office’s address, state



48
49
50
# File 'lib/moxiworks_platform/office.rb', line 48

def state
  @state
end

#timezoneString

Returns the office’s timezone.

Returns:

  • (String)

    the office’s timezone



83
84
85
# File 'lib/moxiworks_platform/office.rb', line 83

def timezone
  @timezone
end

#twitterString

Returns the office’s twitter handle.

Returns:

  • (String)

    the office’s twitter handle



88
89
90
# File 'lib/moxiworks_platform/office.rb', line 88

def twitter
  @twitter
end

#zip_codeString

Returns the office’s address, zip code.

Returns:

  • (String)

    the office’s address, zip code



53
54
55
# File 'lib/moxiworks_platform/office.rb', line 53

def zip_code
  @zip_code
end

Class Method Details

.find(opts = {}) ⇒ MoxiworksPlatform::Office

Find an Office on the Moxi Works Platform

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_office_id (String)

    REQUIRED The Moxi Works Office ID for the office

Returns:

Raises:

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



111
112
113
114
# File 'lib/moxiworks_platform/office.rb', line 111

def self.find(opts={})
  url = "#{MoxiworksPlatform::Config.url}/api/offices/#{opts[:moxi_works_office_id]}"
  self.send_request(:get, opts, url)
end

.search(opts = {}) ⇒ Hash

Search For Offices in Moxi Works Platform

Examples:

results = MoxiworksPlatform::Office.search(
moxi_works_company_id: 'the_company',
page_number: 2
)

Parameters:

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

    named parameter Hash

Options Hash (opts):

  • :moxi_works_company_id (String)

    REQUIRED The Moxi Works Company ID For the search (use Company.search to determine available moxi_works_company_id)

    optional Search parameters

  • :page_number (Integer)

    the page of results to return

Returns:

  • (Hash)

    with the format:

    page_number: [Integer],
    total_pages: [Integer],
    offices:  [Array] containing MoxiworkPlatform::Office objects
    

Raises:

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



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/moxiworks_platform/office.rb', line 154

def self.search(opts={})
  url = "#{MoxiworksPlatform::Config.url}/api/offices"
  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
  results = MoxiResponseArray.new()
  json = { 'page_number': 1, 'total_pages': 0, 'offices':[]}
  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 = json['page_number'] if(json.is_a?(Hash) && json['page_number'])
    results.total_pages = json['total_pages'] if(json.is_a?(Hash) && json['total_pages'])

    json['offices'].each do |r|
      results << MoxiworksPlatform::Office.new(r) unless r.nil? or r.empty?
    end
    json['offices'] = results
  end
  json
end

.send_request(method, opts = {}, url = nil) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
# File 'lib/moxiworks_platform/office.rb', line 116

def self.send_request(method, opts={}, url=nil)
  url ||= "#{MoxiworksPlatform::Config.url}/api/offices"
  required_opts = [:moxi_works_office_id]
  raise ::MoxiworksPlatform::Exception::ArgumentError,
        'arguments must be passed as named parameters' unless opts.is_a? Hash
  required_opts.each do |opt|
    raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
        opts[opt].nil? or opts[opt].to_s.empty?
  end
  super(method, opts, url)
end