Class: MoxiworksPlatform::Office

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

Overview

Moxi Works Platform Office

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

#addressString

Returns the office’s address, street and number.

Returns:

  • (String)

    the office’s address, street and number



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

def address
  @address
end

#address2String

Returns address cont. (ex. suite number).

Returns:

  • (String)

    address cont. (ex. suite number)



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

def address2
  @address2
end

#alt_phoneString

Returns the office’s alternate phone number.

Returns:

  • (String)

    the office’s alternate phone number



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

def alt_phone
  @alt_phone
end

#cityString

Returns the office’s address, city.

Returns:

  • (String)

    the office’s address, city



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

def city
  @city
end

#countyString

Returns the office’s address, county.

Returns:

  • (String)

    the office’s address, county



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

def county
  @county
end

#emailString

Returns the office’s email address.

Returns:

  • (String)

    the office’s email address



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

def email
  @email
end

#facebookString

Returns the office’s facebook page URL.

Returns:

  • (String)

    the office’s facebook page URL



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

def facebook
  @facebook
end

#google_plusString

Returns the office’s google_plus account.

Returns:

  • (String)

    the office’s google_plus account



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

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 name of the office.

Returns:

  • (String)

    the name of the office



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

def name
  @name
end

#phoneString

Returns the office’s primary phone number.

Returns:

  • (String)

    the office’s primary phone number



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

def phone
  @phone
end

#stateString

Returns the office’s address, state.

Returns:

  • (String)

    the office’s address, state



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

def state
  @state
end

#timezoneString

Returns the office’s timezone.

Returns:

  • (String)

    the office’s timezone



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

def timezone
  @timezone
end

#twitterString

Returns the office’s twitter handle.

Returns:

  • (String)

    the office’s twitter handle



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

def twitter
  @twitter
end

#zip_codeString

Returns the office’s address, zip code.

Returns:

  • (String)

    the office’s address, zip code



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

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



95
96
97
98
# File 'lib/moxiworks_platform/office.rb', line 95

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



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/moxiworks_platform/office.rb', line 138

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 = []
  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
    self.check_for_error_in_response(response)
    
    json = JSON.parse(response)
    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



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/moxiworks_platform/office.rb', line 100

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