Missionhub 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +53 -0
- data/Rakefile +10 -0
- data/fixtures/vcr_cassettes/auth.yml +162 -0
- data/lib/console.rb +25 -0
- data/lib/missionhub.rb +15 -0
- data/lib/missionhub/address.rb +15 -0
- data/lib/missionhub/api.rb +43 -0
- data/lib/missionhub/person.rb +127 -0
- data/lib/missionhub/version.rb +3 -0
- data/missionhub.gemspec +25 -0
- data/spec/lib/missionhub/address_spec.rb +37 -0
- data/spec/lib/missionhub/api_spec.rb +93 -0
- data/spec/lib/missionhub/person_spec.rb +95 -0
- data/spec/lib/missionhub/version_spec.rb +9 -0
- data/spec/lib/missionhub_spec.rb +21 -0
- data/spec/spec_helper.rb +32 -0
- metadata +166 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
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 [](http://travis-ci.org/Godmedia/Missionhub-gem) [](https://gemnasium.com/Godmedia/Missionhub-gem) [](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,162 @@
|
|
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=12&client_secret=
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 400
|
13
|
+
message: Bad Request
|
14
|
+
headers:
|
15
|
+
Server:
|
16
|
+
- nginx/1.0.14
|
17
|
+
Date:
|
18
|
+
- Wed, 03 Oct 2012 23:29:16 GMT
|
19
|
+
Content-Type:
|
20
|
+
- application/json
|
21
|
+
Transfer-Encoding:
|
22
|
+
- chunked
|
23
|
+
Connection:
|
24
|
+
- keep-alive
|
25
|
+
Status:
|
26
|
+
- '400'
|
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
|
+
X-Request-Id:
|
34
|
+
- 7b1ff696190f4c801aff3c9d946d59ff
|
35
|
+
X-Runtime:
|
36
|
+
- '0.004363'
|
37
|
+
X-Rack-Cache:
|
38
|
+
- invalidate, pass
|
39
|
+
body:
|
40
|
+
encoding: US-ASCII
|
41
|
+
string: ! '{"error":"invalid_client","error_description":"{\"error\": {\"message\":\"Client
|
42
|
+
ID and client secret do not match.\", \"code\": \"52\"}}"}'
|
43
|
+
http_version:
|
44
|
+
recorded_at: Wed, 03 Oct 2012 23:28:06 GMT
|
45
|
+
- request:
|
46
|
+
method: post
|
47
|
+
uri: http://www.missionhub.com/oauth/access_token
|
48
|
+
body:
|
49
|
+
encoding: US-ASCII
|
50
|
+
string: grant_type=none&client_id=12&client_secret=83f84763001c1fb4ce96adc4908b9ba285b510d6
|
51
|
+
headers: {}
|
52
|
+
response:
|
53
|
+
status:
|
54
|
+
code: 200
|
55
|
+
message: OK
|
56
|
+
headers:
|
57
|
+
Server:
|
58
|
+
- nginx/1.0.14
|
59
|
+
Date:
|
60
|
+
- Wed, 03 Oct 2012 23:29:16 GMT
|
61
|
+
Content-Type:
|
62
|
+
- application/json
|
63
|
+
Transfer-Encoding:
|
64
|
+
- chunked
|
65
|
+
Connection:
|
66
|
+
- keep-alive
|
67
|
+
Status:
|
68
|
+
- '200'
|
69
|
+
X-Powered-By:
|
70
|
+
- Phusion Passenger (mod_rails/mod_rack) 3.0.15
|
71
|
+
Cache-Control:
|
72
|
+
- no-store
|
73
|
+
X-Ua-Compatible:
|
74
|
+
- IE=Edge,chrome=1
|
75
|
+
Etag:
|
76
|
+
- ! '"5e899e87b14129ae3a0b4045e60aa034"'
|
77
|
+
X-Request-Id:
|
78
|
+
- 86584ba26c5eca90804362c68b672f07
|
79
|
+
X-Runtime:
|
80
|
+
- '0.012294'
|
81
|
+
X-Rack-Cache:
|
82
|
+
- invalidate, pass
|
83
|
+
body:
|
84
|
+
encoding: US-ASCII
|
85
|
+
string: ! '{"access_token":"e83b007f75ad49d480303f892de884204b7864bc817f0fb547c9d87444c39a75","scope":"contacts,userinfo,contact_assignment,followup_comments,roles,organization_info"}'
|
86
|
+
http_version:
|
87
|
+
recorded_at: Wed, 03 Oct 2012 23:28:06 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[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&person[email_address][email]=mail%40google.com&person[email_address][primary]=0&person[phone_number][number]=021021021&person[phone_number][primary]=0&person[phone_number][location]=mobile&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=e83b007f75ad49d480303f892de884204b7864bc817f0fb547c9d87444c39a75
|
94
|
+
headers: {}
|
95
|
+
response:
|
96
|
+
status:
|
97
|
+
code: 200
|
98
|
+
message: OK
|
99
|
+
headers:
|
100
|
+
Server:
|
101
|
+
- nginx/1.0.14
|
102
|
+
Date:
|
103
|
+
- Wed, 03 Oct 2012 23:29:23 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
|
+
- ! '"74011cce4197da546e01a09a5e8ce450"'
|
118
|
+
Cache-Control:
|
119
|
+
- max-age=0, private, must-revalidate
|
120
|
+
Set-Cookie:
|
121
|
+
- _mh_session=09142d775c25a060139eb5fabbdf1320; path=/; expires=Fri, 05-Oct-2012
|
122
|
+
23:28:37 GMT; HttpOnly
|
123
|
+
X-Request-Id:
|
124
|
+
- cd61e19dd9bcef433ad39e1e8e8b02a6
|
125
|
+
X-Runtime:
|
126
|
+
- '5.300431'
|
127
|
+
X-Rack-Cache:
|
128
|
+
- invalidate, pass
|
129
|
+
body:
|
130
|
+
encoding: US-ASCII
|
131
|
+
string: ! '{"meta":{"request_time":1349306917},"id":"1050"}'
|
132
|
+
http_version:
|
133
|
+
recorded_at: Wed, 03 Oct 2012 23:28:13 GMT
|
134
|
+
- request:
|
135
|
+
method: post
|
136
|
+
uri: http://www.missionhub.com/api/v2/contacts.json
|
137
|
+
body:
|
138
|
+
encoding: US-ASCII
|
139
|
+
string: person[firstName]=Test&person[lastName]=User&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&person[email_address][email]=mail%40google.com&person[email_address][primary]=0&person[phone_number][number]=021021021&person[phone_number][primary]=0&person[phone_number][location]=mobile&answers[4952]=Hello%20World&answers[4953]=R2&answers[4955]=D2&answers[4954][]=&answers[4954][C3]=C3&answers[4954][C4]=C4&org_id=5522&user_id=1615180&access_token=e83b007f75ad49d480303f892de884204b7864bc817f0fb547c9d87444c39a75
|
140
|
+
headers: {}
|
141
|
+
response:
|
142
|
+
status:
|
143
|
+
code: 502
|
144
|
+
message: Bad Gateway
|
145
|
+
headers:
|
146
|
+
Server:
|
147
|
+
- nginx/1.0.14
|
148
|
+
Date:
|
149
|
+
- Wed, 10 Oct 2012 00:41:41 GMT
|
150
|
+
Content-Type:
|
151
|
+
- text/html
|
152
|
+
Connection:
|
153
|
+
- keep-alive
|
154
|
+
Content-Length:
|
155
|
+
- '172'
|
156
|
+
body:
|
157
|
+
encoding: US-ASCII
|
158
|
+
string: ! "<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>502
|
159
|
+
Bad Gateway</h1></center>\r\n<hr><center>nginx/1.2.2</center>\r\n</body>\r\n</html>\r\n"
|
160
|
+
http_version:
|
161
|
+
recorded_at: Wed, 10 Oct 2012 00:40:14 GMT
|
162
|
+
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,43 @@
|
|
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.nil?
|
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
|
+
if !response.parsed_response['error'].nil?
|
37
|
+
raise response.parsed_response['error']
|
38
|
+
else
|
39
|
+
response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'resolv'
|
2
|
+
|
3
|
+
module Missionhub
|
4
|
+
class Person
|
5
|
+
attr_accessor :current_address_attributes, :phone_number, :email_address, :gender, :firstName, :lastName, :answers, :phone_number
|
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 :phone= :phone_number=
|
15
|
+
alias :phone :phone_number
|
16
|
+
|
17
|
+
alias :address :current_address_attributes
|
18
|
+
|
19
|
+
def phone=(phone)
|
20
|
+
raise "Phone must be a Missionhub::Person::Phone" unless phone.kind_of? Missionhub::Person::Phone
|
21
|
+
@phone_number = phone
|
22
|
+
end
|
23
|
+
|
24
|
+
def address=(address)
|
25
|
+
raise "Address must be a Missionhub::Person::Address" unless address.kind_of? Missionhub::Person::Address
|
26
|
+
@current_address_attributes = address
|
27
|
+
end
|
28
|
+
|
29
|
+
def set_answer(id, message)
|
30
|
+
if @answers.nil?
|
31
|
+
@answers = Hash.new
|
32
|
+
end
|
33
|
+
|
34
|
+
if message.is_a?(String) or message.is_a?(Hash) or message.is_a?(Array)
|
35
|
+
if id.is_a?(Integer)
|
36
|
+
if message.is_a?(Array)
|
37
|
+
h = {}
|
38
|
+
count = 0
|
39
|
+
message.each do |v|
|
40
|
+
h[count] = v
|
41
|
+
count += 1
|
42
|
+
end
|
43
|
+
message = h
|
44
|
+
end
|
45
|
+
@answers[id] = message
|
46
|
+
else
|
47
|
+
raise "Invalid type for id"
|
48
|
+
end
|
49
|
+
else
|
50
|
+
raise "Invalid type for message"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_answer(id)
|
55
|
+
@answers[id]
|
56
|
+
end
|
57
|
+
|
58
|
+
def current_address_attributes=(address)
|
59
|
+
raise "Address must be a Missionhub::Person::Address" unless address.kind_of? Missionhub::Person::Address
|
60
|
+
@current_address_attributes = address
|
61
|
+
end
|
62
|
+
|
63
|
+
def phone
|
64
|
+
@phone_number[:number]
|
65
|
+
end
|
66
|
+
|
67
|
+
def phone=(phone)
|
68
|
+
unless phone.empty?
|
69
|
+
@phone_number = {:number => phone.gsub(/[^0-9]/, ""), :primary => 0, :location => "mobile"}
|
70
|
+
else
|
71
|
+
raise "Phone appears to be empty"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def email_address
|
76
|
+
@email_address[:email]
|
77
|
+
end
|
78
|
+
|
79
|
+
def email_address=(email)
|
80
|
+
unless email.empty?
|
81
|
+
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]$/
|
82
|
+
raise "Email does not appear to be valid format"
|
83
|
+
else
|
84
|
+
raise "Email domain name appears to be incorrect" unless validate_email_domain(email)
|
85
|
+
@email_address = {:email => email, :primary => 0}
|
86
|
+
end
|
87
|
+
else
|
88
|
+
raise "Email appears to be empty"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def gender=(gender)
|
93
|
+
if gender == "male" or gender == "female"
|
94
|
+
@gender = gender
|
95
|
+
else
|
96
|
+
raise "Gender must be either male or female"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def validate_email_domain(email)
|
101
|
+
domain = email.match(/\@(.+)/)[1]
|
102
|
+
Resolv::DNS.open do |dns|
|
103
|
+
@mx = dns.getresources(domain, Resolv::DNS::Resource::IN::MX)
|
104
|
+
end
|
105
|
+
@mx.size > 0 ? true : false
|
106
|
+
end
|
107
|
+
|
108
|
+
def full_name
|
109
|
+
@firstName + " " + @lastName
|
110
|
+
end
|
111
|
+
|
112
|
+
def hash
|
113
|
+
hash_to_return = {}
|
114
|
+
self.instance_variables.each do |var|
|
115
|
+
temp = self.instance_variable_get(var)
|
116
|
+
if not temp.nil? and var.to_s != "@mx"
|
117
|
+
if temp.kind_of? Missionhub::Person::Address
|
118
|
+
hash_to_return[var.to_s.gsub("@","")] = temp.hash
|
119
|
+
else
|
120
|
+
hash_to_return[var.to_s.gsub("@","")] = temp
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
return hash_to_return
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/missionhub.gemspec
ADDED
@@ -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,93 @@
|
|
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
|
+
array_answer = ["","C3","C4"]
|
87
|
+
person.set_answer(4954, array_answer)
|
88
|
+
person.phone = "021021021"
|
89
|
+
response = api.create_person(person)
|
90
|
+
response.must_be_instance_of Hash
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,95 @@
|
|
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 Phone" do
|
20
|
+
it "must be able to set phone" do
|
21
|
+
person.phone = "078556821"
|
22
|
+
person.phone.must_equal "078556821"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "Set Email" do
|
27
|
+
it "must throw exception when email is empty" do
|
28
|
+
email_error = lambda { person.email_address = '' }
|
29
|
+
email_error.must_raise RuntimeError
|
30
|
+
end
|
31
|
+
|
32
|
+
it "must throw exception when email has invalid domain" do
|
33
|
+
email_error = lambda { person.email_address = 'mail@example.com' }
|
34
|
+
email_error.must_raise RuntimeError
|
35
|
+
end
|
36
|
+
|
37
|
+
it "must be able to set email" do
|
38
|
+
email = "mail@gmail.com"
|
39
|
+
person.email_address = email
|
40
|
+
person.email_address.must_equal email
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "Set Gender" do
|
45
|
+
it "must throw exception when gender isn't male/female" do
|
46
|
+
gender_error = lambda { person.gender = 'not_gender' }
|
47
|
+
gender_error.must_raise RuntimeError
|
48
|
+
end
|
49
|
+
|
50
|
+
it "must be able to set gender to male" do
|
51
|
+
gender = "male"
|
52
|
+
person.gender = gender
|
53
|
+
person.gender.must_equal gender
|
54
|
+
end
|
55
|
+
|
56
|
+
it "must be able to set gender to female" do
|
57
|
+
gender = "female"
|
58
|
+
person.gender = gender
|
59
|
+
person.gender.must_equal gender
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "Set Name" do
|
64
|
+
it "must be able to set first name" do
|
65
|
+
person.first_name = "First"
|
66
|
+
person.first_name.must_equal "First"
|
67
|
+
end
|
68
|
+
|
69
|
+
it "must be able to set last name" do
|
70
|
+
person.last_name = "Last"
|
71
|
+
person.last_name.must_equal "Last"
|
72
|
+
end
|
73
|
+
|
74
|
+
it "must be able to get full name" do
|
75
|
+
person.first_name = "First"
|
76
|
+
person.last_name = "Last"
|
77
|
+
person.full_name.must_equal "First Last"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "Set Answers" do
|
82
|
+
it "must be able to set survey answer" do
|
83
|
+
id = 1598
|
84
|
+
message = "true"
|
85
|
+
person.set_answer id, message
|
86
|
+
person.get_answer(id).must_equal message
|
87
|
+
end
|
88
|
+
it "must throw exception when answer is wrong type" do
|
89
|
+
id = 1598
|
90
|
+
message = 1
|
91
|
+
address_error = lambda { person.set_answer id, message }
|
92
|
+
address_error.must_raise RuntimeError
|
93
|
+
end
|
94
|
+
end
|
95
|
+
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
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
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
|
+
c.base_uri = 'http://www.Missionhub.com/'
|
20
|
+
c.client_id = 12
|
21
|
+
c.client_secret = '83f84763001c1fb4ce96adc4908b9ba285b510d6'
|
22
|
+
c.org_id = 5522
|
23
|
+
end
|
24
|
+
|
25
|
+
#VCR config
|
26
|
+
|
27
|
+
VCR.configure do |c|
|
28
|
+
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
29
|
+
c.hook_into :webmock # or :fakeweb
|
30
|
+
end
|
31
|
+
|
32
|
+
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Missionhub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Tataihono Nikora
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-10 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: '0'
|
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
|