MissionHub 1.0rc2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in missionhub.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Tataihono Nikora
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # MissionHub Ruby Gem [![Build Status](https://secure.travis-ci.org/Godmedia/missionhub-gem.png)](http://travis-ci.org/Godmedia/missionhub-gem) [![Dependency Status](https://gemnasium.com/Godmedia/missionhub-gem.png)](https://gemnasium.com/Godmedia/missionhub-gem) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Godmedia/missionhub-gem)
2
+ Consume the MissionHub API easily with this Ruby Gem
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'missionhub'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install missionhub
17
+
18
+ ## Usage
19
+
20
+ TODO: Write usage instructions here
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
29
+
30
+ ##License
31
+
32
+ (The MIT License)
33
+
34
+ Copyright (c) 2012 Tataihono Nikora, GodMedia
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ 'Software'), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
51
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
53
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['spec/lib/missionhub/*_spec.rb'] + FileList['spec/lib/*_spec.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,316 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://www.missionhub.com/oauth/access_token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: grant_type=none&client_id=6&client_secret=05fbcedcf2b2ea3958b359b51796b14b1c04c19a
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - nginx/1.0.14
17
+ Date:
18
+ - Tue, 02 Oct 2012 22:34:39 GMT
19
+ Content-Type:
20
+ - application/json
21
+ Transfer-Encoding:
22
+ - chunked
23
+ Connection:
24
+ - keep-alive
25
+ Status:
26
+ - '200'
27
+ X-Powered-By:
28
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
29
+ Cache-Control:
30
+ - no-store
31
+ X-Ua-Compatible:
32
+ - IE=Edge,chrome=1
33
+ Etag:
34
+ - ! '"5433947c658216a0f750764a263167da"'
35
+ X-Request-Id:
36
+ - f7c1b81b77d8afd6dc0599de0598cb2a
37
+ X-Runtime:
38
+ - '0.201593'
39
+ X-Rack-Cache:
40
+ - invalidate, pass
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ! '{"access_token":"11b341eeb9b9d6401944e8310ea82283e3927b1b3a8b77335d0992373b047deb","scope":"contacts,userinfo,contact_assignment,followup_comments,roles,organization_info"}'
44
+ http_version:
45
+ recorded_at: Tue, 02 Oct 2012 22:33:28 GMT
46
+ - request:
47
+ method: post
48
+ uri: http://www.missionhub.com/oauth/access_token
49
+ body:
50
+ encoding: US-ASCII
51
+ string: grant_type=none&client_id=6&client_secret=
52
+ headers: {}
53
+ response:
54
+ status:
55
+ code: 400
56
+ message: Bad Request
57
+ headers:
58
+ Server:
59
+ - nginx/1.0.14
60
+ Date:
61
+ - Tue, 02 Oct 2012 22:34:39 GMT
62
+ Content-Type:
63
+ - application/json
64
+ Transfer-Encoding:
65
+ - chunked
66
+ Connection:
67
+ - keep-alive
68
+ Status:
69
+ - '400'
70
+ X-Powered-By:
71
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
72
+ Cache-Control:
73
+ - no-store
74
+ X-Ua-Compatible:
75
+ - IE=Edge,chrome=1
76
+ X-Request-Id:
77
+ - 830a7ef7ae292f2be4ff646ca5750f5d
78
+ X-Runtime:
79
+ - '0.031778'
80
+ X-Rack-Cache:
81
+ - invalidate, pass
82
+ body:
83
+ encoding: US-ASCII
84
+ string: ! '{"error":"invalid_client","error_description":"{\"error\": {\"message\":\"Client
85
+ ID and client secret do not match.\", \"code\": \"52\"}}"}'
86
+ http_version:
87
+ recorded_at: Tue, 02 Oct 2012 22:33:29 GMT
88
+ - request:
89
+ method: post
90
+ uri: http://www.missionhub.com/api/v2/contacts.json
91
+ body:
92
+ encoding: US-ASCII
93
+ string: person[firstName]=Test&person[lastName]=User&person[email_address]=mail%40google.com&person[gender]=female&person[current_address_attributes][address1]=123%20Somewhere%20St&person[current_address_attributes][address2]=Dept%202500&person[current_address_attributes][city]=Orlando&person[current_address_attributes][country]=US&person[current_address_attributes][state]=FL&person[current_address_attributes][zip]=32832&answers[4952]=Hello%20World&org_id=6774&user_id=1615180&access_token=11b341eeb9b9d6401944e8310ea82283e3927b1b3a8b77335d0992373b047deb
94
+ headers: {}
95
+ response:
96
+ status:
97
+ code: 200
98
+ message: OK
99
+ headers:
100
+ Server:
101
+ - nginx/1.0.14
102
+ Date:
103
+ - Tue, 02 Oct 2012 22:34:41 GMT
104
+ Content-Type:
105
+ - application/json; charset=utf-8
106
+ Transfer-Encoding:
107
+ - chunked
108
+ Connection:
109
+ - keep-alive
110
+ Status:
111
+ - '200'
112
+ X-Powered-By:
113
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
114
+ X-Ua-Compatible:
115
+ - IE=Edge,chrome=1
116
+ Etag:
117
+ - ! '"8f0ddbec1e2c4a3ee368d905e342a557"'
118
+ Cache-Control:
119
+ - max-age=0, private, must-revalidate
120
+ Set-Cookie:
121
+ - _mh_session=0df192db43584bcb75bb8c65cef20f08; path=/; expires=Thu, 04-Oct-2012
122
+ 22:34:39 GMT; HttpOnly
123
+ - logged_in=true; path=/
124
+ X-Request-Id:
125
+ - 75864fbaa173037b73666f912dd09707
126
+ X-Runtime:
127
+ - '0.478109'
128
+ X-Rack-Cache:
129
+ - invalidate, pass
130
+ body:
131
+ encoding: US-ASCII
132
+ string: ! '{"id":2592529,"name":"Test User","assignment":{"assigned_to_person":[],"person_assigned_to":[]},"gender":"female","status":"uncontacted","request_org_id":6774,"first_contact_date":"2012-10-02
133
+ 22:34:38 UTC","date_surveyed":"2012-10-02 22:34:38 UTC","organizational_roles":[]}'
134
+ http_version:
135
+ recorded_at: Tue, 02 Oct 2012 22:33:30 GMT
136
+ - request:
137
+ method: post
138
+ uri: http://www.missionhub.com/api/v2/contacts.json
139
+ body:
140
+ encoding: US-ASCII
141
+ string: person[firstName]=Test&person[lastName]=User&person[email_address]=mail%40google.com&person[gender]=female&person[current_address_attributes][address1]=123%20Somewhere%20St&person[current_address_attributes][address2]=Dept%202500&person[current_address_attributes][city]=Orlando&person[current_address_attributes][country]=US&person[current_address_attributes][state]=FL&person[current_address_attributes][zip]=32832&answers[4952]=Hello%20World&answers[4953]=R2&answers[4955]=D2&answers[4954][2]=C3&answers[4954][3]=C4&org_id=6774&user_id=1615180&access_token=11b341eeb9b9d6401944e8310ea82283e3927b1b3a8b77335d0992373b047deb
142
+ headers: {}
143
+ response:
144
+ status:
145
+ code: 200
146
+ message: OK
147
+ headers:
148
+ Server:
149
+ - nginx/1.0.14
150
+ Date:
151
+ - Tue, 02 Oct 2012 22:38:59 GMT
152
+ Content-Type:
153
+ - application/json; charset=utf-8
154
+ Transfer-Encoding:
155
+ - chunked
156
+ Connection:
157
+ - keep-alive
158
+ Status:
159
+ - '200'
160
+ X-Powered-By:
161
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
162
+ X-Ua-Compatible:
163
+ - IE=Edge,chrome=1
164
+ Etag:
165
+ - ! '"6fb7f46d4c45fe2d3382eaaf2a12bbcf"'
166
+ Cache-Control:
167
+ - max-age=0, private, must-revalidate
168
+ Set-Cookie:
169
+ - _mh_session=eaf0f05cdb6efc004b0a1d1860a2032a; path=/; expires=Thu, 04-Oct-2012
170
+ 22:38:14 GMT; HttpOnly
171
+ - logged_in=true; path=/
172
+ X-Request-Id:
173
+ - c2c3b8a9648d3bbf1e204e0c38a336a4
174
+ X-Runtime:
175
+ - '0.901663'
176
+ X-Rack-Cache:
177
+ - invalidate, pass
178
+ body:
179
+ encoding: US-ASCII
180
+ string: ! '{"id":2592532,"name":"Test User","assignment":{"assigned_to_person":[],"person_assigned_to":[]},"gender":"female","status":"uncontacted","request_org_id":6774,"first_contact_date":"2012-10-02
181
+ 22:38:14 UTC","date_surveyed":"2012-10-02 22:38:14 UTC","organizational_roles":[]}'
182
+ http_version:
183
+ recorded_at: Tue, 02 Oct 2012 22:37:48 GMT
184
+ - request:
185
+ method: post
186
+ uri: http://www.missionhub.com/oauth/access_token
187
+ body:
188
+ encoding: US-ASCII
189
+ string: grant_type=none&client_id=12&client_secret=
190
+ headers: {}
191
+ response:
192
+ status:
193
+ code: 400
194
+ message: Bad Request
195
+ headers:
196
+ Server:
197
+ - nginx/1.0.14
198
+ Date:
199
+ - Tue, 02 Oct 2012 23:12:32 GMT
200
+ Content-Type:
201
+ - application/json
202
+ Transfer-Encoding:
203
+ - chunked
204
+ Connection:
205
+ - keep-alive
206
+ Status:
207
+ - '400'
208
+ X-Powered-By:
209
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
210
+ Cache-Control:
211
+ - no-store
212
+ X-Ua-Compatible:
213
+ - IE=Edge,chrome=1
214
+ X-Request-Id:
215
+ - 91024aeaccf492cc12391d87befaa36b
216
+ X-Runtime:
217
+ - '0.004484'
218
+ X-Rack-Cache:
219
+ - invalidate, pass
220
+ body:
221
+ encoding: US-ASCII
222
+ string: ! '{"error":"invalid_client","error_description":"{\"error\": {\"message\":\"Client
223
+ ID and client secret do not match.\", \"code\": \"52\"}}"}'
224
+ http_version:
225
+ recorded_at: Tue, 02 Oct 2012 23:11:21 GMT
226
+ - request:
227
+ method: post
228
+ uri: http://www.missionhub.com/oauth/access_token
229
+ body:
230
+ encoding: US-ASCII
231
+ string: grant_type=none&client_id=12&client_secret=83f84763001c1fb4ce96adc4908b9ba285b510d6
232
+ headers: {}
233
+ response:
234
+ status:
235
+ code: 200
236
+ message: OK
237
+ headers:
238
+ Server:
239
+ - nginx/1.0.14
240
+ Date:
241
+ - Tue, 02 Oct 2012 23:12:32 GMT
242
+ Content-Type:
243
+ - application/json
244
+ Transfer-Encoding:
245
+ - chunked
246
+ Connection:
247
+ - keep-alive
248
+ Status:
249
+ - '200'
250
+ X-Powered-By:
251
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
252
+ Cache-Control:
253
+ - no-store
254
+ X-Ua-Compatible:
255
+ - IE=Edge,chrome=1
256
+ Etag:
257
+ - ! '"8e7d0338744d5a62ee5c240f3f2ebb30"'
258
+ X-Request-Id:
259
+ - 399d5091e15a9b4621d55060d10b3f58
260
+ X-Runtime:
261
+ - '0.012341'
262
+ X-Rack-Cache:
263
+ - invalidate, pass
264
+ body:
265
+ encoding: US-ASCII
266
+ string: ! '{"access_token":"03a6f575b13657a0dad1b6ff07a099d9088fed26617758dd374b0c985a502a79","scope":"contacts,userinfo,contact_assignment,followup_comments,roles,organization_info"}'
267
+ http_version:
268
+ recorded_at: Tue, 02 Oct 2012 23:11:22 GMT
269
+ - request:
270
+ method: post
271
+ uri: http://www.missionhub.com/api/v2/contacts.json
272
+ body:
273
+ encoding: US-ASCII
274
+ string: person[firstName]=Test&person[lastName]=User&person[email_address]=mail%40google.com&person[gender]=female&person[current_address_attributes][address1]=123%20Somewhere%20St&person[current_address_attributes][address2]=Dept%202500&person[current_address_attributes][city]=Orlando&person[current_address_attributes][country]=US&person[current_address_attributes][state]=FL&person[current_address_attributes][zip]=32832&answers[4952]=Hello%20World&answers[4953]=R2&answers[4955]=D2&answers[4954][2]=C3&answers[4954][3]=C4&org_id=5522&user_id=1615180&access_token=03a6f575b13657a0dad1b6ff07a099d9088fed26617758dd374b0c985a502a79
275
+ headers: {}
276
+ response:
277
+ status:
278
+ code: 200
279
+ message: OK
280
+ headers:
281
+ Server:
282
+ - nginx/1.0.14
283
+ Date:
284
+ - Tue, 02 Oct 2012 23:12:50 GMT
285
+ Content-Type:
286
+ - application/json; charset=utf-8
287
+ Transfer-Encoding:
288
+ - chunked
289
+ Connection:
290
+ - keep-alive
291
+ Status:
292
+ - '200'
293
+ X-Powered-By:
294
+ - Phusion Passenger (mod_rails/mod_rack) 3.0.15
295
+ X-Ua-Compatible:
296
+ - IE=Edge,chrome=1
297
+ Etag:
298
+ - ! '"fa696d44203f05b4311fbf064e85e2d0"'
299
+ Cache-Control:
300
+ - max-age=0, private, must-revalidate
301
+ Set-Cookie:
302
+ - _mh_session=76da570805214bd26bb6301dac676ad5; path=/; expires=Thu, 04-Oct-2012
303
+ 23:12:05 GMT; HttpOnly
304
+ X-Request-Id:
305
+ - 2fecf45d93bc215c4e407a6c5cfa8ad0
306
+ X-Runtime:
307
+ - '5.431635'
308
+ X-Rack-Cache:
309
+ - invalidate, pass
310
+ body:
311
+ encoding: US-ASCII
312
+ string: ! '{"meta":{"request_time":1349219525},"error":"undefined method `user''
313
+ for nil:NilClass"}'
314
+ http_version:
315
+ recorded_at: Tue, 02 Oct 2012 23:11:39 GMT
316
+ recorded_with: VCR 2.2.5
data/lib/console.rb ADDED
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '/missionhub.rb'))
2
+ puts <<-TXT
3
+ Ruby lib for working with the MissionHub API's JSON interface.
4
+ The first thing you need to set is the Base URI for communicating
5
+ with your MissionHub Instance.
6
+
7
+ MissionHub.base_uri = 'http://www.missionhub.com/'
8
+
9
+ Then, you should set the authentication. You can find more info
10
+ on API Authentication at http://wiki.uscm.org/display/NCO/Authentication.
11
+
12
+ #OAuth Two Legged Authentication
13
+ MissionHub.client_id = 1
14
+ MissionHub.client_secret = '32jk248bkjf0875sdasjloy'
15
+
16
+ This library is a small wrapper around the REST interface.
17
+
18
+ TXT
19
+
20
+ MissionHub.config do |c|
21
+ # :outline - turn's original case/test outline mode [default]
22
+ c.base_uri = 'http://www.missionhub.com/'
23
+ c.client_id = 6
24
+ c.client_secret = '5b1913aa85720d7ede99dac1ad35fbf40bbc4490d9da0df346877832469daeb2'
25
+ end
data/lib/missionhub.rb ADDED
@@ -0,0 +1,15 @@
1
+ Dir[File.dirname(__FILE__) + '/missionhub/*.rb'].each do |file|
2
+ require file
3
+ end
4
+
5
+ module MissionHub
6
+ extend self
7
+
8
+ attr_accessor :client_id, :client_secret, :base_uri, :org_id
9
+
10
+ # And we define a wrapper for the configuration block, that we'll use to set up
11
+ # our set of options
12
+ def config(&block)
13
+ instance_eval(&block)
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module MissionHub
2
+ class Person
3
+ class Address
4
+ attr_accessor :address1, :address2, :city, :country, :state, :zip
5
+
6
+ def hash
7
+ hash_to_return = {}
8
+ self.instance_variables.each do |var|
9
+ hash_to_return[var.to_s.gsub("@","")] = self.instance_variable_get(var)
10
+ end
11
+ hash_to_return
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+ require 'httparty'
3
+
4
+ module MissionHub
5
+ class API
6
+ include HTTParty
7
+
8
+ @access_token = ''
9
+ @scope = Array[]
10
+
11
+ def initialize
12
+ self.class.base_uri MissionHub.base_uri
13
+ end
14
+
15
+ def auth
16
+ options = {:body => { :grant_type => 'none', :client_id => MissionHub.client_id, :client_secret => MissionHub.client_secret } }
17
+ response = self.class.post('/oauth/access_token', options)
18
+ raise 'invalid client' if response.parsed_response['access_token'].nil?
19
+ @access_token = response.parsed_response['access_token']
20
+ raise 'invalid scope' if response.parsed_response['scope'].nil?
21
+ @scope = response.parsed_response['scope'].split(',')
22
+ true
23
+ end
24
+
25
+ def create_person(person)
26
+ raise "Not Authenticated" if @access_token.empty?
27
+ raise "Scope doesn't allow for contact creation" unless @scope.include?("contacts")
28
+ raise "Peron must be a MissionHub::Person" unless person.kind_of? MissionHub::Person
29
+ raise "First name must be set to create person" if person.first_name.nil?
30
+
31
+ #hard_coded user_id (given by developer of API)
32
+ person_hash = person.hash
33
+ person_hash.delete("answers")
34
+ options = {:body => { :person => person_hash, :answers => person.answers, :org_id => MissionHub.org_id, :user_id => 1615180, :access_token => @access_token} }
35
+ response = self.class.post('/api/v2/contacts.json', options)
36
+ response["id"].to_i
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,94 @@
1
+ require 'resolv'
2
+
3
+ module MissionHub
4
+ class Person
5
+ attr_accessor :current_address_attributes, :phone_number, :email_address, :gender, :firstName, :lastName, :answers
6
+
7
+ #align variable naming with MissionHub API
8
+ alias :first_name= :firstName=
9
+ alias :first_name :firstName
10
+
11
+ alias :last_name= :lastName=
12
+ alias :last_name :lastName
13
+
14
+ alias :address :current_address_attributes
15
+
16
+ def address=(address)
17
+ raise "Address must be a MissionHub::Person::Address" unless address.kind_of? MissionHub::Person::Address
18
+ @current_address_attributes = address
19
+ end
20
+
21
+ def set_answer(id, message)
22
+ if @answers.nil?
23
+ @answers = Hash.new
24
+ end
25
+
26
+ if message.is_a?(String) or message.is_a?(Hash)
27
+ if id.is_a?(Integer)
28
+ @answers[id] = message
29
+ else
30
+ raise "Invalid type for id"
31
+ end
32
+ else
33
+ raise "Invalid type for message"
34
+ end
35
+ end
36
+
37
+ def get_answer(id)
38
+ @answers[id]
39
+ end
40
+
41
+ def current_address_attributes=(address)
42
+ raise "Address must be a MissionHub::Person::Address" unless address.kind_of? MissionHub::Person::Address
43
+ @current_address_attributes = address
44
+ end
45
+
46
+ def email_address=(email)
47
+ unless email.empty?
48
+ unless email =~ /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
49
+ raise "Email does not appear to be valid format"
50
+ else
51
+ raise "Email domain name appears to be incorrect" unless validate_email_domain(email)
52
+ @email_address = email
53
+ end
54
+ else
55
+ raise "Email appears to be empty"
56
+ end
57
+ end
58
+
59
+ def gender=(gender)
60
+ if gender == "male" or gender == "female"
61
+ @gender = gender
62
+ else
63
+ raise "Gender must be either male or female"
64
+ end
65
+ end
66
+
67
+ def validate_email_domain(email)
68
+ domain = email.match(/\@(.+)/)[1]
69
+ Resolv::DNS.open do |dns|
70
+ @mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
71
+ end
72
+ @mx.size > 0 ? true : false
73
+ end
74
+
75
+ def full_name
76
+ @firstName + " " + @lastName
77
+ end
78
+
79
+ def hash
80
+ hash_to_return = {}
81
+ self.instance_variables.each do |var|
82
+ temp = self.instance_variable_get(var)
83
+ if not temp.nil? and var.to_s != "@mx"
84
+ if not temp.kind_of? MissionHub::Person::Address
85
+ hash_to_return[var.to_s.gsub("@","")] = temp
86
+ else
87
+ hash_to_return[var.to_s.gsub("@","")] = temp.hash
88
+ end
89
+ end
90
+ end
91
+ return hash_to_return
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,3 @@
1
+ module MissionHub
2
+ VERSION = "1.0rc2"
3
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/missionhub/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Tataihono Nikora"]
6
+ gem.email = ["tataihono.nikora@gmail.com"]
7
+ gem.description = %q{Consume the MissionHub API easily with this Ruby Gem}
8
+ gem.summary = %q{MissionHub API for Ruby}
9
+ gem.homepage = "https://github.com/Godmedia/missionhub-gem"
10
+
11
+ gem.add_development_dependency 'minitest'
12
+ gem.add_development_dependency 'webmock'
13
+ gem.add_development_dependency 'vcr'
14
+ gem.add_development_dependency 'turn'
15
+ gem.add_development_dependency 'rake'
16
+
17
+ gem.add_dependency "httparty", "~> 0.9.0"
18
+
19
+ gem.files = `git ls-files`.split($\)
20
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
+ gem.name = "MissionHub"
23
+ gem.require_paths = ["lib"]
24
+ gem.version = MissionHub::VERSION
25
+ end
@@ -0,0 +1,37 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MissionHub::Person::Address do
4
+
5
+ let(:address) { MissionHub::Person::Address.new }
6
+
7
+ it "must be able to set address1" do
8
+ address.address1 = "71 Harrow Street"
9
+ address.address1.must_equal "71 Harrow Street"
10
+ end
11
+
12
+ it "must be able to set address2" do
13
+ address.address2 = "North Dunedin"
14
+ address.address2.must_equal "North Dunedin"
15
+ end
16
+
17
+ it "must be able to set city" do
18
+ address.city = "Dunedin"
19
+ address.city.must_equal "Dunedin"
20
+ end
21
+
22
+ it "must be able to set country" do
23
+ address.country = "NZ"
24
+ address.country.must_equal "NZ"
25
+ end
26
+
27
+ it "must be able to set state" do
28
+ address.state = "Otago"
29
+ address.state.must_equal "Otago"
30
+ end
31
+
32
+ it "must be able to set zip" do
33
+ address.zip = "9016"
34
+ address.zip.must_equal "9016"
35
+ end
36
+
37
+ end
@@ -0,0 +1,90 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MissionHub::API do
4
+
5
+ describe "Defaults" do
6
+
7
+ it "must include httparty methods" do
8
+ MissionHub::API.must_include HTTParty
9
+ end
10
+
11
+ end
12
+
13
+ describe "Authentication" do
14
+
15
+ let(:api) { MissionHub::API.new }
16
+
17
+ before do
18
+ VCR.insert_cassette 'auth', :record => :new_episodes, :match_requests_on => [:body]
19
+ end
20
+
21
+ after do
22
+ VCR.eject_cassette
23
+ end
24
+
25
+ it "must have a auth method" do
26
+ api.must_respond_to :auth
27
+ end
28
+
29
+ it "must throw exception when auth is incorrect" do
30
+ temp = MissionHub.client_secret
31
+ MissionHub.client_secret = ''
32
+
33
+ auth_error = lambda { api.auth }
34
+ auth_error.must_raise RuntimeError
35
+
36
+ MissionHub.client_secret = temp
37
+ end
38
+
39
+ it "must authenticate properly" do
40
+ api.auth.must_equal true
41
+ end
42
+ end
43
+
44
+ describe "Person" do
45
+
46
+ let(:api) { MissionHub::API.new }
47
+
48
+ before do
49
+ VCR.insert_cassette 'auth', :record => :new_episodes, :match_requests_on => [:body]
50
+ api.auth
51
+ end
52
+
53
+ after do
54
+ VCR.eject_cassette
55
+ end
56
+
57
+ it "must throw exception when person is wrong type" do
58
+ person_set_error = lambda { api.create_person('') }
59
+ person_set_error.must_raise RuntimeError
60
+ end
61
+
62
+ it "must throw exception when person has no name" do
63
+ person_set_error = lambda { api.create_person(MissionHub::Person.new) }
64
+ person_set_error.must_raise RuntimeError
65
+ end
66
+
67
+ it "must be able to create person" do
68
+ person = MissionHub::Person.new
69
+ person.first_name = "Test"
70
+ person.last_name = "User"
71
+ address = MissionHub::Person::Address.new
72
+ address.address1 = "123 Somewhere St"
73
+ address.address2 = "Dept 2500"
74
+ address.city = "Orlando"
75
+ address.country = "US"
76
+ address.state = "FL"
77
+ address.zip = "32832"
78
+ person.address = address
79
+ person.email_address = "mail@google.com"
80
+ person.gender = "female"
81
+ person.set_answer(4952, "Hello World")
82
+ person.set_answer(4953, "R2")
83
+ person.set_answer(4955, "D2")
84
+ hash_answer = {"2" => "C3", "3" => "C4"}
85
+ person.set_answer(4954, hash_answer)
86
+ response = api.create_person(person)
87
+ response.must_be_instance_of Fixnum
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,88 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MissionHub::Person do
4
+ let(:person) { MissionHub::Person.new }
5
+
6
+ describe "Set Address" do
7
+ it "must throw exception when address is wrong type" do
8
+ address_error = lambda { person.address = '' }
9
+ address_error.must_raise RuntimeError
10
+ end
11
+
12
+ it "must be able to set address" do
13
+ address = MissionHub::Person::Address.new
14
+ person.address = address
15
+ person.address.must_equal address
16
+ end
17
+ end
18
+
19
+ describe "Set Email" do
20
+ it "must throw exception when email is empty" do
21
+ email_error = lambda { person.email_address = '' }
22
+ email_error.must_raise RuntimeError
23
+ end
24
+
25
+ it "must throw exception when email has invalid domain" do
26
+ email_error = lambda { person.email_address = 'mail@example.com' }
27
+ email_error.must_raise RuntimeError
28
+ end
29
+
30
+ it "must be able to set email" do
31
+ email = "mail@gmail.com"
32
+ person.email_address = email
33
+ person.email_address.must_equal email
34
+ end
35
+ end
36
+
37
+ describe "Set Gender" do
38
+ it "must throw exception when gender isn't male/female" do
39
+ gender_error = lambda { person.gender = 'not_gender' }
40
+ gender_error.must_raise RuntimeError
41
+ end
42
+
43
+ it "must be able to set gender to male" do
44
+ gender = "male"
45
+ person.gender = gender
46
+ person.gender.must_equal gender
47
+ end
48
+
49
+ it "must be able to set gender to female" do
50
+ gender = "female"
51
+ person.gender = gender
52
+ person.gender.must_equal gender
53
+ end
54
+ end
55
+
56
+ describe "Set Name" do
57
+ it "must be able to set first name" do
58
+ person.first_name = "First"
59
+ person.first_name.must_equal "First"
60
+ end
61
+
62
+ it "must be able to set last name" do
63
+ person.last_name = "Last"
64
+ person.last_name.must_equal "Last"
65
+ end
66
+
67
+ it "must be able to get full name" do
68
+ person.first_name = "First"
69
+ person.last_name = "Last"
70
+ person.full_name.must_equal "First Last"
71
+ end
72
+ end
73
+
74
+ describe "Set Answers" do
75
+ it "must be able to set survey answer" do
76
+ id = 1598
77
+ message = "true"
78
+ person.set_answer id, message
79
+ person.get_answer(id).must_equal message
80
+ end
81
+ it "must throw exception when answer is wrong type" do
82
+ id = 1598
83
+ message = 1
84
+ address_error = lambda { person.set_answer id, message }
85
+ address_error.must_raise RuntimeError
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MissionHub, "Version" do
4
+
5
+ it "must have version set" do
6
+ MissionHub::VERSION.wont_be_nil
7
+ end
8
+
9
+ end
@@ -0,0 +1,21 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe MissionHub do
4
+
5
+ it "must have the base url set to the MissionHub API" do
6
+ MissionHub.base_uri.must_equal 'http://www.missionhub.com/'
7
+ end
8
+
9
+ it "must have a defined client id" do
10
+ MissionHub.client_id.wont_be_nil
11
+ end
12
+
13
+ it "must have a defined client secret" do
14
+ MissionHub.client_secret.wont_be_empty
15
+ end
16
+
17
+ it "must have a defined organization id" do
18
+ MissionHub.org_id.wont_be_nil
19
+ end
20
+
21
+ end
@@ -0,0 +1,33 @@
1
+ #we need the actual library file
2
+ require_relative '../lib/missionhub'
3
+ #dependencies
4
+ require 'minitest/autorun'
5
+ require 'webmock/minitest'
6
+ require 'vcr'
7
+ require 'turn'
8
+
9
+ Turn.config do |c|
10
+ # :outline - turn's original casetest outline mode [default]
11
+ c.format = :outline
12
+ # turn on invokeexecute tracing, enable full backtrace
13
+ c.trace = 100
14
+ # use humanized test names (works only with :outline format)
15
+ c.natural = true
16
+ end
17
+
18
+ MissionHub.config do |c|
19
+ # :outline - turn's original case/test outline mode [default]
20
+ c.base_uri = 'http://www.missionhub.com/'
21
+ c.client_id = 12
22
+ c.client_secret = '83f84763001c1fb4ce96adc4908b9ba285b510d6'
23
+ c.org_id = 5522
24
+ end
25
+
26
+ #VCR config
27
+
28
+ VCR.configure do |c|
29
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
30
+ c.hook_into :webmock # or :fakeweb
31
+ end
32
+
33
+
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MissionHub
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0rc2
5
+ prerelease: 3
6
+ platform: ruby
7
+ authors:
8
+ - Tataihono Nikora
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: minitest
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: vcr
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: turn
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: httparty
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 0.9.0
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.0
110
+ description: Consume the MissionHub API easily with this Ruby Gem
111
+ email:
112
+ - tataihono.nikora@gmail.com
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - .gitignore
118
+ - Gemfile
119
+ - LICENSE
120
+ - README.md
121
+ - Rakefile
122
+ - fixtures/vcr_cassettes/auth.yml
123
+ - lib/console.rb
124
+ - lib/missionhub.rb
125
+ - lib/missionhub/address.rb
126
+ - lib/missionhub/api.rb
127
+ - lib/missionhub/person.rb
128
+ - lib/missionhub/version.rb
129
+ - missionhub.gemspec
130
+ - spec/lib/missionhub/address_spec.rb
131
+ - spec/lib/missionhub/api_spec.rb
132
+ - spec/lib/missionhub/person_spec.rb
133
+ - spec/lib/missionhub/version_spec.rb
134
+ - spec/lib/missionhub_spec.rb
135
+ - spec/spec_helper.rb
136
+ homepage: https://github.com/Godmedia/missionhub-gem
137
+ licenses: []
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>'
152
+ - !ruby/object:Gem::Version
153
+ version: 1.3.1
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.24
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: MissionHub API for Ruby
160
+ test_files:
161
+ - spec/lib/missionhub/address_spec.rb
162
+ - spec/lib/missionhub/api_spec.rb
163
+ - spec/lib/missionhub/person_spec.rb
164
+ - spec/lib/missionhub/version_spec.rb
165
+ - spec/lib/missionhub_spec.rb
166
+ - spec/spec_helper.rb