toopher_api 1.0.4 → 1.0.5

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.
@@ -19,7 +19,9 @@ while secret.nil? or secret.empty?
19
19
  secret.chomp!
20
20
  end
21
21
 
22
- toopher = ToopherAPI.new(key, secret)
22
+ url = ENV['TOOPHER_BASE_URL']
23
+ puts 'using base url = ' + url
24
+ toopher = ToopherAPI.new(key, secret, url)
23
25
 
24
26
  puts 'STEP 1: Pair device'
25
27
  puts 'enter pairing phrase:'
@@ -43,7 +45,7 @@ puts 'STEP 2: Authenticate login'
43
45
  puts 'enter terminal name:'
44
46
  terminal_name = gets;
45
47
  terminal_name.chomp!
46
- puts 'enter action name, or [ENTER] for none:'
48
+ puts 'enter action name, or press [ENTER] for the default action ("log in"):'
47
49
  while (true)
48
50
  action = gets;
49
51
  action.chomp!
@@ -57,6 +59,8 @@ while (true)
57
59
  auth = toopher.get_authentication_status(auth.id)
58
60
  end
59
61
 
60
- puts "Successfully authorized action '" + action + "'. Enter another action to authorize again, or [Ctrl-C] to exit"
62
+ automation = auth.automated ? 'automatically ' : ''
63
+ result = auth.granted ? 'granted' : 'denied'
64
+ puts 'The request was ' + automation + result + "! Enter another action to authorize again, or [Ctrl-C] to exit"
61
65
  end
62
66
 
@@ -61,11 +61,11 @@ class ToopherAPI
61
61
  # @param [String] user_name A human recognizable string which represents the user making the request (usually their username). This is displayed to the user on the mobile app when authenticating.
62
62
  #
63
63
  # @return [PairingStatus] Information about the pairing request
64
- def pair(pairing_phrase, user_name)
64
+ def pair(pairing_phrase, user_name, options = {})
65
65
  return PairingStatus.new(post('pairings/create', {
66
66
  'pairing_phrase' => pairing_phrase,
67
67
  'user_name' => user_name
68
- }))
68
+ }.merge(options)))
69
69
  end
70
70
 
71
71
  # Check on the status of a previous pairing request
@@ -84,13 +84,13 @@ class ToopherAPI
84
84
  # @param [String] action_name Optional action name, defaults to "log in" (displayed to the user)
85
85
  #
86
86
  # @return [AuthenticationStatus] Information about the authentication request
87
- def authenticate(pairing_id, terminal_name, action_name = '')
87
+ def authenticate(pairing_id, terminal_name = '', action_name = '', options = {})
88
88
  parameters = {
89
89
  'pairing_id' => pairing_id,
90
90
  'terminal_name' => terminal_name
91
91
  }
92
92
  action_name.empty? or (parameters['action_name'] = action_name)
93
- return AuthenticationStatus.new(post('authentication_requests/initiate', parameters))
93
+ return AuthenticationStatus.new(post('authentication_requests/initiate', parameters.merge(options)))
94
94
  end
95
95
 
96
96
  # Check on the status of a previous authentication request
@@ -146,11 +146,16 @@ class PairingStatus
146
146
  # @return [String] The human recognizable user name associated with the given id.
147
147
  attr_accessor :user_name
148
148
 
149
+ # @!attribute raw
150
+ # @return [hash] The raw data returned from the Toopher API
151
+ attr_accessor :raw
152
+
149
153
  def initialize(json_obj)
150
154
  @id = json_obj['id']
151
155
  @enabled = json_obj['enabled']
152
156
  @user_id = json_obj['user']['id']
153
157
  @user_name = json_obj['user']['name']
158
+ @raw = json_obj
154
159
  end
155
160
  end
156
161
 
@@ -185,6 +190,10 @@ class AuthenticationStatus
185
190
  # @return [String] The human recognizable terminal name associated with the given id.
186
191
  attr_accessor :terminal_name
187
192
 
193
+ # @!attribute raw
194
+ # @return [hash] The raw data returned from the Toopher API
195
+ attr_accessor :raw
196
+
188
197
  def initialize(json_obj)
189
198
  @id = json_obj['id']
190
199
  @pending = json_obj['pending']
@@ -193,5 +202,6 @@ class AuthenticationStatus
193
202
  @reason = json_obj['reason']
194
203
  @terminal_id = json_obj['terminal']['id']
195
204
  @terminal_name = json_obj['terminal']['name']
205
+ @raw = json_obj
196
206
  end
197
207
  end
@@ -25,7 +25,7 @@ class TestToopher < Test::Unit::TestCase
25
25
  end
26
26
 
27
27
  def test_create_pairing_immediate_success()
28
- stub_http_request(:post, "https://toopher-api.appspot.com/v1/pairings/create").
28
+ stub_http_request(:post, "https://toopher.test/v1/pairings/create").
29
29
  with(
30
30
  # :headers => {
31
31
  # 'Authorization' => 'OAuth oauth_consumer_key="key",oauth_nonce="nonce",oauth_signature="%2FW9rUAFDuJTTBtfSxeQ%2FDxWpVQY%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="0",oauth_version="1.0"'
@@ -37,27 +37,46 @@ class TestToopher < Test::Unit::TestCase
37
37
  :status => 200
38
38
  )
39
39
 
40
- toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' })
40
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
41
41
  pairing = toopher.pair('immediate_pair', 'user')
42
42
  assert(pairing.id == '1', 'bad pairing id')
43
43
  assert(pairing.enabled == true, 'pairing not enabled')
44
44
  assert(pairing.user_id == '1', 'bad user id')
45
45
  assert(pairing.user_name == 'user', 'bad user name')
46
+ assert(pairing.raw['user']['name'] == 'user', 'could not access raw data')
47
+ end
48
+
49
+ def test_create_pairing_with_optional_arg()
50
+ stub_http_request(:post, "https://toopher.test/v1/pairings/create").
51
+ with(
52
+ :body => { 'pairing_phrase' => 'immediate_pair', 'user_name' => 'user' , 'test_param' => 'foo'}
53
+ ).
54
+ to_return(
55
+ :body => '{"id":"1","enabled":true,"user":{"id":"1","name":"user"}}',
56
+ :status => 200
57
+ )
46
58
 
59
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
60
+ pairing = toopher.pair('immediate_pair', 'user', :test_param => 'foo')
61
+ assert(pairing.id == '1', 'bad pairing id')
62
+ assert(pairing.enabled == true, 'pairing not enabled')
63
+ assert(pairing.user_id == '1', 'bad user id')
64
+ assert(pairing.user_name == 'user', 'bad user name')
47
65
  end
66
+
48
67
  def test_get_pairing_status()
49
- stub_http_request(:get, "https://toopher-api.appspot.com/v1/pairings/1").
68
+ stub_http_request(:get, "https://toopher.test/v1/pairings/1").
50
69
  to_return(
51
70
  :body => '{"id":"1","enabled":true,"user":{"id":"1","name":"paired user"}}',
52
71
  :status => 200
53
72
  )
54
- stub_http_request(:get, "https://toopher-api.appspot.com/v1/pairings/2").
73
+ stub_http_request(:get, "https://toopher.test/v1/pairings/2").
55
74
  to_return(
56
75
  :body => '{"id":"2","enabled":false,"user":{"id":"2","name":"unpaired user"}}',
57
76
  :status => 200
58
77
  )
59
78
 
60
- toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' })
79
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
61
80
  pairing = toopher.get_pairing_status('1')
62
81
  assert(pairing.id == '1', 'bad pairing id')
63
82
  assert(pairing.enabled == true, 'pairing not enabled')
@@ -72,7 +91,7 @@ class TestToopher < Test::Unit::TestCase
72
91
  end
73
92
 
74
93
  def test_create_authentication_with_no_action()
75
- stub_http_request(:post, "https://toopher-api.appspot.com/v1/authentication_requests/initiate").
94
+ stub_http_request(:post, "https://toopher.test/v1/authentication_requests/initiate").
76
95
  with(
77
96
  :body => { 'pairing_id' => '1', 'terminal_name' => 'term name' }
78
97
  ).
@@ -81,7 +100,7 @@ class TestToopher < Test::Unit::TestCase
81
100
  :status => 200
82
101
  )
83
102
 
84
- toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' })
103
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
85
104
  auth = toopher.authenticate('1', 'term name')
86
105
  assert(auth.id == '1', 'wrong auth id')
87
106
  assert(auth.pending == false, 'wrong auth pending')
@@ -92,19 +111,40 @@ class TestToopher < Test::Unit::TestCase
92
111
  assert(auth.terminal_name == 'term name', 'wrong auth terminal name')
93
112
  end
94
113
 
114
+ def test_create_authentication_with_optional_arg()
115
+ stub_http_request(:post, "https://toopher.test/v1/authentication_requests/initiate").
116
+ with(
117
+ :body => { 'pairing_id' => '1', 'terminal_name' => 'term name', 'test_param' => 'foo' }
118
+ ).
119
+ to_return(
120
+ :body => '{"id":"1","pending":false,"granted":true,"automated":true,"reason":"some reason","terminal":{"id":"1","name":"term name"}}',
121
+ :status => 200
122
+ )
123
+
124
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
125
+ auth = toopher.authenticate('1', 'term name', '', {'test_param' => 'foo'})
126
+ assert(auth.id == '1', 'wrong auth id')
127
+ assert(auth.pending == false, 'wrong auth pending')
128
+ assert(auth.granted == true, 'wrong auth granted')
129
+ assert(auth.automated == true, 'wrong auth automated')
130
+ assert(auth.reason == 'some reason', 'wrong auth reason')
131
+ assert(auth.terminal_id == '1', 'wrong auth terminal id')
132
+ assert(auth.terminal_name == 'term name', 'wrong auth terminal name')
133
+ end
134
+
95
135
  def test_get_authentication_status()
96
- stub_http_request(:get, "https://toopher-api.appspot.com/v1/authentication_requests/1").
136
+ stub_http_request(:get, "https://toopher.test/v1/authentication_requests/1").
97
137
  to_return(
98
138
  :body => '{"id":"1","pending":false,"granted":true,"automated":true,"reason":"some reason","terminal":{"id":"1","name":"term name"}}',
99
139
  :status => 200
100
140
  )
101
- stub_http_request(:get, "https://toopher-api.appspot.com/v1/authentication_requests/2").
141
+ stub_http_request(:get, "https://toopher.test/v1/authentication_requests/2").
102
142
  to_return(
103
143
  :body => '{"id":"2","pending":true,"granted":false,"automated":false,"reason":"some other reason","terminal":{"id":"2","name":"another term name"}}',
104
144
  :status => 200
105
145
  )
106
146
 
107
- toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' })
147
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
108
148
  auth = toopher.get_authentication_status('1')
109
149
  assert(auth.id == '1', 'wrong auth id')
110
150
  assert(auth.pending == false, 'wrong auth pending')
@@ -113,6 +153,7 @@ class TestToopher < Test::Unit::TestCase
113
153
  assert(auth.reason == 'some reason', 'wrong auth reason')
114
154
  assert(auth.terminal_id == '1', 'wrong auth terminal id')
115
155
  assert(auth.terminal_name == 'term name', 'wrong auth terminal name')
156
+ assert(auth.raw['terminal']['name'] == 'term name', 'could not access raw data')
116
157
 
117
158
  auth = toopher.get_authentication_status('2')
118
159
  assert(auth.id == '2', 'wrong auth id')
@@ -122,15 +163,16 @@ class TestToopher < Test::Unit::TestCase
122
163
  assert(auth.reason == 'some other reason', 'wrong auth reason')
123
164
  assert(auth.terminal_id == '2', 'wrong auth terminal id')
124
165
  assert(auth.terminal_name == 'another term name', 'wrong auth terminal name')
166
+ assert(auth.raw['terminal']['name'] == 'another term name', 'could not access raw data')
125
167
  end
126
168
 
127
169
  def test_toopher_request_error()
128
- stub_http_request(:get, "https://toopher-api.appspot.com/v1/authentication_requests/1").
170
+ stub_http_request(:get, "https://toopher.test/v1/authentication_requests/1").
129
171
  to_return(
130
172
  :body => '{"error_code":401,"error_message":"Not a valid OAuth signed request"}',
131
173
  :status => 401
132
174
  )
133
- toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' })
175
+ toopher = ToopherAPI.new('key', 'secret', {:nonce => 'nonce', :timestamp => '0' }, base_url="https://toopher.test/v1/")
134
176
  assert_raise ToopherApiError do
135
177
  auth = toopher.get_authentication_status('1')
136
178
  end
metadata CHANGED
@@ -1,131 +1,113 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: toopher_api
3
- version: !ruby/object:Gem::Version
4
- hash: 31
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 4
10
- version: 1.0.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Toopher, Inc.
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-12-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-08-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: oauth
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 1
29
- segments:
30
- - 0
31
- - 4
32
- - 7
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 0.4.7
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: json
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
40
33
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 1
45
- segments:
46
- - 1
47
- - 7
48
- - 5
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
49
37
  version: 1.7.5
50
38
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: webmock
54
39
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.7.5
46
+ - !ruby/object:Gem::Dependency
47
+ name: webmock
48
+ requirement: !ruby/object:Gem::Requirement
56
49
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 51
61
- segments:
62
- - 1
63
- - 9
64
- - 0
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
65
53
  version: 1.9.0
66
54
  type: :development
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: yard
70
55
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.9.0
62
+ - !ruby/object:Gem::Dependency
63
+ name: yard
64
+ requirement: !ruby/object:Gem::Requirement
72
65
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- hash: 57
77
- segments:
78
- - 0
79
- - 8
80
- - 3
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
81
69
  version: 0.8.3
82
70
  type: :development
83
- version_requirements: *id004
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.8.3
84
78
  description: Synchronous interface to the toopher.com authentication api.
85
79
  email: support@toopher.com
86
80
  executables: []
87
-
88
81
  extensions: []
89
-
90
82
  extra_rdoc_files: []
91
-
92
- files:
83
+ files:
93
84
  - Rakefile
94
85
  - lib/toopher_api.rb
95
86
  - test/test_toopher_api.rb
96
87
  - demo/toopher_demo.rb
97
88
  homepage: http://dev.toopher.com
98
89
  licenses: []
99
-
100
90
  post_install_message:
101
91
  rdoc_options: []
102
-
103
- require_paths:
92
+ require_paths:
104
93
  - lib
105
- required_ruby_version: !ruby/object:Gem::Requirement
94
+ required_ruby_version: !ruby/object:Gem::Requirement
106
95
  none: false
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- hash: 3
111
- segments:
112
- - 0
113
- version: "0"
114
- required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
101
  none: false
116
- requirements:
117
- - - ">="
118
- - !ruby/object:Gem::Version
119
- hash: 3
120
- segments:
121
- - 0
122
- version: "0"
102
+ requirements:
103
+ - - ! '>='
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
123
106
  requirements: []
124
-
125
107
  rubyforge_project:
126
- rubygems_version: 1.8.24
108
+ rubygems_version: 1.8.25
127
109
  signing_key:
128
110
  specification_version: 3
129
111
  summary: Interface to the toopher.com authentication api
130
112
  test_files: []
131
-
113
+ has_rdoc: