MissionHub 2.0.0 → 2.1.0

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/Gemfile CHANGED
@@ -1,7 +1,4 @@
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
-
6
3
  # Specify your gem's dependencies in missionhub.gemspec
7
4
  gemspec
data/Rakefile CHANGED
@@ -7,4 +7,8 @@ Rake::TestTask.new do |t|
7
7
  t.verbose = true
8
8
  end
9
9
 
10
+ task :console do
11
+ sh "irb -rubygems -I lib -r missionhub.rb"
12
+ end
13
+
10
14
  task :default => :test
@@ -3,16 +3,8 @@ Dir[File.dirname(__FILE__) + '/missionhub/*.rb'].each do |file|
3
3
  end
4
4
 
5
5
  module MissionHub
6
+ extend Config
6
7
  class << self
7
- attr_accessor :client_id, :client_secret, :site
8
8
 
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
13
-
14
- self.site ||= "https://www.missionhub.com/apis/v3"
15
- Base.site = site
16
- end
17
9
  end
18
10
  end
@@ -1,9 +1,9 @@
1
+ require 'active_resource'
1
2
  module MissionHub
2
3
  class Base < ActiveResource::Base
3
-
4
4
  def self.connection(refresh = false)
5
5
  if defined?(@connection) || superclass == Object
6
- @connection = Connection.new(site, format) if refresh || @connection.nil?
6
+ @connection = MissionHub::Connection.new(site, format) if refresh || @connection.nil?
7
7
  @connection.proxy = proxy if proxy
8
8
  @connection.auth_type = auth_type if auth_type
9
9
  @connection.timeout = timeout if timeout
@@ -33,8 +33,11 @@ module MissionHub
33
33
  end
34
34
 
35
35
  def add_secret_to_path(path)
36
- path += path.include?('?') ? '&' : '?'
37
- path + "secret=#{MissionHub.client_secret}"
36
+ unless path.include?('secret=')
37
+ path += path.include?('?') ? '&' : '?'
38
+ path += "secret=#{Thread.current["mission_hub.client_secret"]}"
39
+ end
40
+ path
38
41
  end
39
42
  end
40
43
  end
@@ -0,0 +1,57 @@
1
+
2
+ require 'missionhub/version'
3
+
4
+ module MissionHub
5
+ # Defines constants and methods related to configuration
6
+ module Config
7
+
8
+
9
+ # The API Key if none is set
10
+ DEFAULT_CLIENT_SECRET = nil
11
+
12
+ # The endpoint that will be used to connect if none is set
13
+ DEFAULT_SITE = 'https://www.missionhub.com/apis/v3'
14
+
15
+ # An array of valid keys in the options hash when configuring a {Twitter::Client}
16
+ VALID_OPTIONS_KEYS = [
17
+ :client_secret,
18
+ :site
19
+ ]
20
+
21
+ # When this module is extended, set all configuration options to their default values
22
+ def self.extended(base)
23
+ base.reset
24
+ end
25
+
26
+ VALID_OPTIONS_KEYS.each do |attr|
27
+ define_method(attr) do
28
+ Thread.current["mission_hub.#{attr}"]
29
+ end
30
+
31
+ define_method("#{attr}=") do |val|
32
+ Thread.current["mission_hub.#{attr}"] = val
33
+ end
34
+ end
35
+
36
+ # Convenience method to allow configuration options to be set in a block
37
+ def config
38
+ yield self
39
+ Base.site = Thread.current["mission_hub.site"]
40
+ self
41
+ end
42
+
43
+ # Create a hash of options and their values
44
+ def options
45
+ options = {}
46
+ VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
47
+ options
48
+ end
49
+
50
+ # Reset all configuration options to defaults
51
+ def reset
52
+ self.client_secret = DEFAULT_CLIENT_SECRET
53
+ self.site = DEFAULT_SITE
54
+ self
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module MissionHub
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
@@ -10,11 +10,12 @@ 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 "activeresource", "~> 4.0.0.beta"
17
+ gem.add_dependency "activeresource"
18
+ gem.add_dependency "activemodel"
18
19
 
19
20
  gem.files = `git ls-files`.split($\)
20
21
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -3,19 +3,11 @@ 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://stage.missionhub.com/'
7
- end
8
-
9
- it "must have a defined client id" do
10
- MissionHub.client_id.wont_be_nil
6
+ MissionHub.site.must_equal 'https://www.missionhub.com/apis/v3'
11
7
  end
12
8
 
13
9
  it "must have a defined client secret" do
14
10
  MissionHub.client_secret.wont_be_empty
15
11
  end
16
12
 
17
- it "must have a defined organization id" do
18
- MissionHub.org_id.wont_be_nil
19
- end
20
-
21
13
  end
@@ -1,5 +1,5 @@
1
1
  #we need the actual library file
2
- require_relative '../lib/missionhub'
2
+ require_relative '../lib/MissionHub'
3
3
  #dependencies
4
4
  require 'minitest/autorun'
5
5
  require 'webmock/minitest'
@@ -16,17 +16,12 @@ Turn.config do |c|
16
16
  end
17
17
 
18
18
  MissionHub.config do |c|
19
- c.base_uri = 'http://stage.missionhub.com/'
20
- c.client_id = 12
21
- c.client_secret = '33f84763tasf9c1fb4ce96adc4908b9ba285b510d0'
22
- c.org_id = 5522
19
+ c.client_secret = '9d1211dfbd048192ef27047911a4554b10befb5deb870c85e15060ca9b8758f8'
23
20
  end
24
21
 
25
- #VCR config
26
-
27
22
  VCR.configure do |c|
28
23
  c.cassette_library_dir = 'fixtures/vcr_cassettes'
29
- c.hook_into :webmock # or :fakeweb
24
+ c.hook_into :webmock
30
25
  end
31
26
 
32
27
 
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: 2.0.0
4
+ version: 2.1.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-12-18 00:00:00.000000000 Z
12
+ date: 2013-02-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
@@ -43,6 +43,22 @@ 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'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: turn
48
64
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +91,38 @@ dependencies:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: activeresource
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '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'
110
+ - !ruby/object:Gem::Dependency
111
+ name: activemodel
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
78
126
  description: Consume the MissionHub API easily with this Ruby Gem
79
127
  email:
80
128
  - tataihono.nikora@gmail.com
@@ -87,9 +135,9 @@ files:
87
135
  - LICENSE
88
136
  - README.md
89
137
  - Rakefile
90
- - fixtures/vcr_cassettes/auth.yml
91
138
  - lib/missionhub.rb
92
139
  - lib/missionhub/base.rb
140
+ - lib/missionhub/config.rb
93
141
  - lib/missionhub/email_address.rb
94
142
  - lib/missionhub/followup_comment.rb
95
143
  - lib/missionhub/organization.rb
@@ -103,9 +151,6 @@ files:
103
151
  - lib/missionhub/survey.rb
104
152
  - lib/missionhub/version.rb
105
153
  - missionhub.gemspec
106
- - spec/lib/missionhub/address_spec.rb
107
- - spec/lib/missionhub/api_spec.rb
108
- - spec/lib/missionhub/person_spec.rb
109
154
  - spec/lib/missionhub/version_spec.rb
110
155
  - spec/lib/missionhub_spec.rb
111
156
  - spec/spec_helper.rb
@@ -134,9 +179,6 @@ signing_key:
134
179
  specification_version: 3
135
180
  summary: MissionHub API for Ruby
136
181
  test_files:
137
- - spec/lib/missionhub/address_spec.rb
138
- - spec/lib/missionhub/api_spec.rb
139
- - spec/lib/missionhub/person_spec.rb
140
182
  - spec/lib/missionhub/version_spec.rb
141
183
  - spec/lib/missionhub_spec.rb
142
184
  - spec/spec_helper.rb
@@ -1,135 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: http://stage.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
- - Thu, 08 Nov 2012 13:49:26 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
- - 19536bac31ccee8569a1bdae781b7648
35
- X-Runtime:
36
- - '0.123355'
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: Thu, 08 Nov 2012 13:47:09 GMT
45
- - request:
46
- method: post
47
- uri: http://stage.missionhub.com/oauth/access_token
48
- body:
49
- encoding: US-ASCII
50
- string: grant_type=none&client_id=12&client_secret=33f84763tasf9c1fb4ce96adc4908b9ba285b510d0
51
- headers: {}
52
- response:
53
- status:
54
- code: 200
55
- message: OK
56
- headers:
57
- Server:
58
- - nginx/1.0.14
59
- Date:
60
- - Thu, 08 Nov 2012 13:49:27 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
- - ! '"587793cf9f81936d3aa19ce565ea19cf"'
77
- X-Request-Id:
78
- - aae32e7e7ecd9ee631f7e24d277b0778
79
- X-Runtime:
80
- - '0.047424'
81
- X-Rack-Cache:
82
- - invalidate, pass
83
- body:
84
- encoding: US-ASCII
85
- string: ! '{"access_token":"526bba947bfeb5a7d60206c75983dcf30aee5a68ef7bc7479c7a151cdce3c7e8","scope":"contacts,userinfo,contact_assignment,followup_comments,roles,organization_info"}'
86
- http_version:
87
- recorded_at: Thu, 08 Nov 2012 13:47:10 GMT
88
- - request:
89
- method: post
90
- uri: http://stage.missionhub.com/api/v2/contacts.json
91
- body:
92
- encoding: US-ASCII
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
- headers: {}
95
- response:
96
- status:
97
- code: 200
98
- message: OK
99
- headers:
100
- Server:
101
- - nginx/1.0.14
102
- Date:
103
- - Thu, 08 Nov 2012 13:49:28 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
- - ! '"e081d0440636fc4cf4a95aa23fc06f6b"'
118
- Cache-Control:
119
- - max-age=0, private, must-revalidate
120
- Set-Cookie:
121
- - _mh_session=d3e7b5065853a46631c59b937c6674de; path=/; expires=Sat, 10-Nov-2012
122
- 13:50:24 GMT; HttpOnly
123
- - logged_in=true; path=/
124
- X-Request-Id:
125
- - d27fa3266be6e14b41b311a106a38ee0
126
- X-Runtime:
127
- - '0.195808'
128
- X-Rack-Cache:
129
- - invalidate, pass
130
- body:
131
- encoding: US-ASCII
132
- string: ! '{"id":2592834,"name":"Test User","assignment":{"assigned_to_person":[],"person_assigned_to":[]},"gender":"Female","status":"uncontacted","request_org_id":5522,"organizational_roles":[]}'
133
- http_version:
134
- recorded_at: Thu, 08 Nov 2012 13:47:11 GMT
135
- recorded_with: VCR 2.3.0
@@ -1,37 +0,0 @@
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
@@ -1,93 +0,0 @@
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
@@ -1,95 +0,0 @@
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