MissionHub 1.0.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor/ruby
data/Gemfile CHANGED
@@ -1,4 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'activeresource', require: 'active_resource', git: 'git://github.com/rails/activeresource.git'
4
+ gem 'activemodel', git: 'git://github.com/rails/rails.git'
5
+
3
6
  # Specify your gem's dependencies in missionhub.gemspec
4
7
  gemspec
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: post
5
- uri: http://www.missionhub.com/oauth/access_token
5
+ uri: http://stage.missionhub.com/oauth/access_token
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: grant_type=none&client_id=12&client_secret=
@@ -15,7 +15,7 @@ http_interactions:
15
15
  Server:
16
16
  - nginx/1.0.14
17
17
  Date:
18
- - Wed, 03 Oct 2012 23:29:16 GMT
18
+ - Thu, 08 Nov 2012 13:49:26 GMT
19
19
  Content-Type:
20
20
  - application/json
21
21
  Transfer-Encoding:
@@ -31,9 +31,9 @@ http_interactions:
31
31
  X-Ua-Compatible:
32
32
  - IE=Edge,chrome=1
33
33
  X-Request-Id:
34
- - 7b1ff696190f4c801aff3c9d946d59ff
34
+ - 19536bac31ccee8569a1bdae781b7648
35
35
  X-Runtime:
36
- - '0.004363'
36
+ - '0.123355'
37
37
  X-Rack-Cache:
38
38
  - invalidate, pass
39
39
  body:
@@ -41,13 +41,13 @@ http_interactions:
41
41
  string: ! '{"error":"invalid_client","error_description":"{\"error\": {\"message\":\"Client
42
42
  ID and client secret do not match.\", \"code\": \"52\"}}"}'
43
43
  http_version:
44
- recorded_at: Wed, 03 Oct 2012 23:28:06 GMT
44
+ recorded_at: Thu, 08 Nov 2012 13:47:09 GMT
45
45
  - request:
46
46
  method: post
47
- uri: http://www.missionhub.com/oauth/access_token
47
+ uri: http://stage.missionhub.com/oauth/access_token
48
48
  body:
49
49
  encoding: US-ASCII
50
- string: grant_type=none&client_id=12&client_secret=83f84763001c1fb4ce96adc4908b9ba285b510d6
50
+ string: grant_type=none&client_id=12&client_secret=33f84763tasf9c1fb4ce96adc4908b9ba285b510d0
51
51
  headers: {}
52
52
  response:
53
53
  status:
@@ -57,7 +57,7 @@ http_interactions:
57
57
  Server:
58
58
  - nginx/1.0.14
59
59
  Date:
60
- - Wed, 03 Oct 2012 23:29:16 GMT
60
+ - Thu, 08 Nov 2012 13:49:27 GMT
61
61
  Content-Type:
62
62
  - application/json
63
63
  Transfer-Encoding:
@@ -73,24 +73,24 @@ http_interactions:
73
73
  X-Ua-Compatible:
74
74
  - IE=Edge,chrome=1
75
75
  Etag:
76
- - ! '"5e899e87b14129ae3a0b4045e60aa034"'
76
+ - ! '"587793cf9f81936d3aa19ce565ea19cf"'
77
77
  X-Request-Id:
78
- - 86584ba26c5eca90804362c68b672f07
78
+ - aae32e7e7ecd9ee631f7e24d277b0778
79
79
  X-Runtime:
80
- - '0.012294'
80
+ - '0.047424'
81
81
  X-Rack-Cache:
82
82
  - invalidate, pass
83
83
  body:
84
84
  encoding: US-ASCII
85
- string: ! '{"access_token":"e83b007f75ad49d480303f892de884204b7864bc817f0fb547c9d87444c39a75","scope":"contacts,userinfo,contact_assignment,followup_comments,roles,organization_info"}'
85
+ string: ! '{"access_token":"526bba947bfeb5a7d60206c75983dcf30aee5a68ef7bc7479c7a151cdce3c7e8","scope":"contacts,userinfo,contact_assignment,followup_comments,roles,organization_info"}'
86
86
  http_version:
87
- recorded_at: Wed, 03 Oct 2012 23:28:06 GMT
87
+ recorded_at: Thu, 08 Nov 2012 13:47:10 GMT
88
88
  - request:
89
89
  method: post
90
- uri: http://www.missionhub.com/api/v2/contacts.json
90
+ uri: http://stage.missionhub.com/api/v2/contacts.json
91
91
  body:
92
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
93
+ string: person[first_name]=Test&person[last_name]=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][0]=&answers[4954][1]=C3&answers[4954][2]=C4&org_id=5522&user_id=1615180&access_token=526bba947bfeb5a7d60206c75983dcf30aee5a68ef7bc7479c7a151cdce3c7e8
94
94
  headers: {}
95
95
  response:
96
96
  status:
@@ -100,7 +100,7 @@ http_interactions:
100
100
  Server:
101
101
  - nginx/1.0.14
102
102
  Date:
103
- - Wed, 03 Oct 2012 23:29:23 GMT
103
+ - Thu, 08 Nov 2012 13:49:28 GMT
104
104
  Content-Type:
105
105
  - application/json; charset=utf-8
106
106
  Transfer-Encoding:
@@ -114,49 +114,22 @@ http_interactions:
114
114
  X-Ua-Compatible:
115
115
  - IE=Edge,chrome=1
116
116
  Etag:
117
- - ! '"74011cce4197da546e01a09a5e8ce450"'
117
+ - ! '"e081d0440636fc4cf4a95aa23fc06f6b"'
118
118
  Cache-Control:
119
119
  - max-age=0, private, must-revalidate
120
120
  Set-Cookie:
121
- - _mh_session=09142d775c25a060139eb5fabbdf1320; path=/; expires=Fri, 05-Oct-2012
122
- 23:28:37 GMT; HttpOnly
121
+ - _mh_session=d3e7b5065853a46631c59b937c6674de; path=/; expires=Sat, 10-Nov-2012
122
+ 13:50:24 GMT; HttpOnly
123
+ - logged_in=true; path=/
123
124
  X-Request-Id:
124
- - cd61e19dd9bcef433ad39e1e8e8b02a6
125
+ - d27fa3266be6e14b41b311a106a38ee0
125
126
  X-Runtime:
126
- - '5.300431'
127
+ - '0.195808'
127
128
  X-Rack-Cache:
128
129
  - invalidate, pass
129
130
  body:
130
131
  encoding: US-ASCII
131
- string: ! '{"meta":{"request_time":1349306917},"id":"1050"}'
132
+ string: ! '{"id":2592834,"name":"Test User","assignment":{"assigned_to_person":[],"person_assigned_to":[]},"gender":"Female","status":"uncontacted","request_org_id":5522,"organizational_roles":[]}'
132
133
  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
134
+ recorded_at: Thu, 08 Nov 2012 13:47:11 GMT
135
+ recorded_with: VCR 2.3.0
@@ -1,15 +1,18 @@
1
- Dir[File.dirname(__FILE__) + '/MissionHub/*.rb'].each do |file|
1
+ Dir[File.dirname(__FILE__) + '/missionhub/*.rb'].each do |file|
2
2
  require file
3
3
  end
4
4
 
5
5
  module MissionHub
6
- extend self
6
+ class << self
7
+ attr_accessor :client_id, :client_secret, :site
7
8
 
8
- attr_accessor :client_id, :client_secret, :base_uri, :org_id
9
+ # And we define a wrapper for the configuration block, that we'll use to set up
10
+ # our set of options
11
+ def config
12
+ yield self
9
13
 
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
+ self.site ||= "https://www.missionhub.com/apis/v3"
15
+ Base.site = site
16
+ end
14
17
  end
15
18
  end
@@ -0,0 +1,40 @@
1
+ module MissionHub
2
+ class Base < ActiveResource::Base
3
+
4
+ def self.connection(refresh = false)
5
+ if defined?(@connection) || superclass == Object
6
+ @connection = Connection.new(site, format) if refresh || @connection.nil?
7
+ @connection.proxy = proxy if proxy
8
+ @connection.auth_type = auth_type if auth_type
9
+ @connection.timeout = timeout if timeout
10
+ @connection
11
+ else
12
+ superclass.connection
13
+ end
14
+ end
15
+ end
16
+
17
+ class Connection < ActiveResource::Connection
18
+
19
+ private
20
+
21
+ def request(method, path, *arguments)
22
+ result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
23
+ path = add_secret_to_path(path)
24
+ payload[:method] = method
25
+ payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
26
+ payload[:result] = http.send(method, path, *arguments)
27
+ end
28
+ handle_response(result)
29
+ rescue Timeout::Error => e
30
+ raise TimeoutError.new(e.message)
31
+ rescue OpenSSL::SSL::SSLError => e
32
+ raise SSLError.new(e.message)
33
+ end
34
+
35
+ def add_secret_to_path(path)
36
+ path += path.include?('?') ? '&' : '?'
37
+ path + "secret=#{MissionHub.client_secret}"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class EmailAddress < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class FollowupComment < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class Organization < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class OrganizationalRole < Base
3
+
4
+ end
5
+ end
@@ -1,127 +1,5 @@
1
- require 'resolv'
2
-
3
1
  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
2
+ class Person < Base
111
3
 
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
4
  end
127
5
  end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class PhoneNumber < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class Question < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class Rejoicable < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class Role < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class SmsKeyword < Base
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module MissionHub
2
+ class Survey < Base
3
+
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module MissionHub
2
- VERSION = "1.0.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/MissionHub/version', __FILE__)
2
+ require File.expand_path('../lib/missionhub/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Tataihono Nikora"]
@@ -10,11 +10,11 @@ Gem::Specification.new do |gem|
10
10
 
11
11
  gem.add_development_dependency 'minitest'
12
12
  gem.add_development_dependency 'webmock'
13
- gem.add_development_dependency 'vcr'
13
+ #gem.add_development_dependency 'vcr'
14
14
  gem.add_development_dependency 'turn'
15
15
  gem.add_development_dependency 'rake'
16
16
 
17
- gem.add_dependency "httparty", "~> 0.9.0"
17
+ #gem.add_dependency "activeresource", "~> 4.0.0.beta"
18
18
 
19
19
  gem.files = `git ls-files`.split($\)
20
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -3,7 +3,7 @@ require_relative '../spec_helper'
3
3
  describe MissionHub do
4
4
 
5
5
  it "must have the base url set to the MissionHub API" do
6
- MissionHub.base_uri.must_equal 'http://www.missionhub.com/'
6
+ MissionHub.base_uri.must_equal 'http://stage.missionhub.com/'
7
7
  end
8
8
 
9
9
  it "must have a defined client id" do
@@ -16,9 +16,9 @@ Turn.config do |c|
16
16
  end
17
17
 
18
18
  MissionHub.config do |c|
19
- c.base_uri = 'http://www.missionhub.com/'
19
+ c.base_uri = 'http://stage.missionhub.com/'
20
20
  c.client_id = 12
21
- c.client_secret = '83f84763001c1fb4ce96adc4908b9ba285b510d6'
21
+ c.client_secret = '33f84763tasf9c1fb4ce96adc4908b9ba285b510d0'
22
22
  c.org_id = 5522
23
23
  end
24
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MissionHub
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2012-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
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
46
  - !ruby/object:Gem::Dependency
63
47
  name: turn
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -91,22 +75,6 @@ dependencies:
91
75
  - - ! '>='
92
76
  - !ruby/object:Gem::Version
93
77
  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
78
  description: Consume the MissionHub API easily with this Ruby Gem
111
79
  email:
112
80
  - tataihono.nikora@gmail.com
@@ -120,11 +88,19 @@ files:
120
88
  - README.md
121
89
  - Rakefile
122
90
  - fixtures/vcr_cassettes/auth.yml
123
- - lib/console.rb
124
91
  - lib/missionhub.rb
125
- - lib/missionhub/address.rb
126
- - lib/missionhub/api.rb
92
+ - lib/missionhub/base.rb
93
+ - lib/missionhub/email_address.rb
94
+ - lib/missionhub/followup_comment.rb
95
+ - lib/missionhub/organization.rb
96
+ - lib/missionhub/organizational_role.rb
127
97
  - lib/missionhub/person.rb
98
+ - lib/missionhub/phone_number.rb
99
+ - lib/missionhub/question.rb
100
+ - lib/missionhub/rejoicable.rb
101
+ - lib/missionhub/role.rb
102
+ - lib/missionhub/sms_keyword.rb
103
+ - lib/missionhub/survey.rb
128
104
  - lib/missionhub/version.rb
129
105
  - missionhub.gemspec
130
106
  - spec/lib/missionhub/address_spec.rb
@@ -1,25 +0,0 @@
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
@@ -1,15 +0,0 @@
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
@@ -1,43 +0,0 @@
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