moxiworks_platform 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,165 @@
1
+ module MoxiworksPlatform
2
+ # = Moxi Works Platform Office
3
+ class Office < MoxiworksPlatform::Resource
4
+
5
+ # @!attribute moxi_works_office_id
6
+ #
7
+ # @return [String] the UUID of the office
8
+ attr_accessor :moxi_works_office_id
9
+
10
+ # @!attribute image_url
11
+ #
12
+ # @return [String] a URL to an image of the office.
13
+ attr_accessor :image_url
14
+
15
+ # @!attribute name
16
+ #
17
+ # @return [String] the name of the office
18
+ attr_accessor :name
19
+
20
+ # @!attribute address
21
+ #
22
+ # @return [String] the office's address, street and number
23
+ attr_accessor :address
24
+
25
+ # @!attribute address2
26
+ #
27
+ # @return [String] address cont. (ex. suite number)
28
+ attr_accessor :address2
29
+
30
+ # @!attribute city
31
+ #
32
+ # @return [String] the office's address, city
33
+ attr_accessor :city
34
+
35
+ # @!attribute county
36
+ #
37
+ # @return [String] the office's address, county
38
+ attr_accessor :county
39
+
40
+ # @!attribute state
41
+ #
42
+ # @return [String] the office's address, state
43
+ attr_accessor :state
44
+
45
+ # @!attribute zip_code
46
+ #
47
+ # @return [String] the office's address, zip code
48
+ attr_accessor :zip_code
49
+
50
+ # @!attribute alt_phone
51
+ #
52
+ # @return [String] the office's alternate phone number
53
+ attr_accessor :alt_phone
54
+
55
+ # @!attribute email
56
+ #
57
+ # @return [String] the office's email address
58
+ attr_accessor :email
59
+
60
+ # @!attribute facebook
61
+ #
62
+ # @return [String] the office's facebook page URL
63
+ attr_accessor :facebook
64
+
65
+ # @!attribute google_plus
66
+ #
67
+ # @return [String] the office's google_plus account
68
+ attr_accessor :google_plus
69
+
70
+ # @!attribute phone
71
+ #
72
+ # @return [String] the office's primary phone number
73
+ attr_accessor :phone
74
+
75
+ # @!attribute timezone
76
+ #
77
+ # @return [String] the office's timezone
78
+ attr_accessor :timezone
79
+
80
+ # @!attribute twitter
81
+ #
82
+ # @return [String] the office's twitter handle
83
+ attr_accessor :twitter
84
+
85
+
86
+ # Find an Office on the Moxi Works Platform
87
+ # @param [Hash] opts named parameter Hash
88
+ # @option opts [String] :moxi_works_office_id *REQUIRED* The Moxi Works Office ID for the office
89
+ #
90
+ # @return [MoxiworksPlatform::Office]
91
+ #
92
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
93
+ # named parameters aren't included
94
+ #
95
+ def self.find(opts={})
96
+ url = "#{MoxiworksPlatform::Config.url}/api/offices/#{opts[:moxi_works_office_id]}"
97
+ self.send_request(:get, opts, url)
98
+ end
99
+
100
+ def self.send_request(method, opts={}, url=nil)
101
+ url ||= "#{MoxiworksPlatform::Config.url}/api/offices"
102
+ required_opts = [:moxi_works_office_id]
103
+ raise ::MoxiworksPlatform::Exception::ArgumentError,
104
+ 'arguments must be passed as named parameters' unless opts.is_a? Hash
105
+ required_opts.each do |opt|
106
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
107
+ opts[opt].nil? or opts[opt].to_s.empty?
108
+ end
109
+ super(method, opts, url)
110
+ end
111
+
112
+ # Search For Offices in Moxi Works Platform
113
+ # @param [Hash] opts named parameter Hash
114
+ # @option opts [String] :moxi_works_company_id *REQUIRED* The Moxi Works Company ID For the search (use Company.search to determine available moxi_works_company_id)
115
+ #
116
+ #
117
+ # optional Search parameters
118
+ #
119
+ # @option opts [Integer] :page_number the page of results to return
120
+ #
121
+ # @return [Hash] with the format:
122
+ # {
123
+ # page_number: [Integer],
124
+ # total_pages: [Integer],
125
+ # offices: [Array] containing MoxiworkPlatform::Office objects
126
+ # }
127
+ #
128
+ #
129
+ # @raise ::MoxiworksPlatform::Exception::ArgumentError if required
130
+ # named parameters aren't included
131
+ #
132
+ # @example
133
+ # results = MoxiworksPlatform::Office.search(
134
+ # moxi_works_company_id: 'the_company',
135
+ # page_number: 2
136
+ # )
137
+ #
138
+ def self.search(opts={})
139
+ url = "#{MoxiworksPlatform::Config.url}/api/offices"
140
+ required_opts = [:moxi_works_company_id]
141
+ required_opts.each do |opt|
142
+ raise ::MoxiworksPlatform::Exception::ArgumentError, "#{opt} required" if
143
+ opts[opt].nil? or opts[opt].to_s.empty?
144
+ end
145
+ results = []
146
+ json = { 'page_number': 1, 'total_pages': 0, 'offices':[]}
147
+ RestClient::Request.execute(method: :get,
148
+ url: url,
149
+ payload: opts, headers: self.headers) do |response|
150
+ puts response if MoxiworksPlatform::Config.debug
151
+ self.check_for_error_in_response(response)
152
+ json = JSON.parse(response)
153
+ json['offices'].each do |r|
154
+ results << MoxiworksPlatform::Office.new(r) unless r.nil? or r.empty?
155
+ end
156
+ json['offices'] = results
157
+ end
158
+ json
159
+ end
160
+
161
+
162
+ end
163
+
164
+
165
+ end
@@ -79,6 +79,10 @@ module MoxiworksPlatform
79
79
  # maps Hash values to Instance variables for mapping JSON object values to our Class attributes
80
80
  #
81
81
  def initialize(hash={})
82
+ self.init_attrs_from_hash(hash)
83
+ end
84
+
85
+ def init_attrs_from_hash(hash={})
82
86
  hash.each do |key,val|
83
87
  instance_variable_set("@#{key}", val)
84
88
  end
@@ -125,7 +129,7 @@ module MoxiworksPlatform
125
129
  val = self.instance_variable_get("@#{attr_name}")
126
130
  return val.to_i if val.is_a? Numeric and opts[:type] == :integer
127
131
  return val if val.is_a? Numeric
128
- return 0 if val.nil? or val.empty?
132
+ return nil if val.nil? or val.empty?
129
133
  val.gsub!(/[^[:digit:]|\.]/, '') if val.is_a? String
130
134
  case opts[:type]
131
135
  when :integer