synapse_client 0.1.3 → 0.1.4
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1383017e5b19893e1e5a72491da9ca52acfb5160
|
4
|
+
data.tar.gz: 1a7fd28f77a7f4a030907c890c0c0a90300367b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5afe0053efeaf1ba4b0b55859afb5283b7dd4bc18470ea93ce7dae8a5d18b8743fff0d505f637bea7c1b72f987b62239affa3feaf7222453a57a9a484f58732d
|
7
|
+
data.tar.gz: bf5d82448ff3e4129de3f7fa29494af779cdf89c96ec07aa90211a6ad0d6f474766f8a9471358866537e9b6c2182b72369fe3aaadb47ebd20bc027aa1c356cd6
|
data/lib/synapse_client.rb
CHANGED
@@ -94,11 +94,15 @@ module SynapseClient
|
|
94
94
|
}
|
95
95
|
|
96
96
|
#
|
97
|
-
|
97
|
+
begin
|
98
98
|
response = execute_request(request_opts)
|
99
99
|
# TODO: https://github.com/stripe/stripe-ruby/blob/master/lib/stripe.rb#L127
|
100
|
-
|
101
|
-
|
100
|
+
rescue RestClient::Exception, Errno::ECONNREFUSED => e
|
101
|
+
return SynapseClient::APIOperations::Response.new({
|
102
|
+
:success => false,
|
103
|
+
:status_code => e.http_code
|
104
|
+
})
|
105
|
+
end
|
102
106
|
|
103
107
|
parse(response)
|
104
108
|
end
|
@@ -3,17 +3,19 @@ module SynapseClient
|
|
3
3
|
class Response
|
4
4
|
attr_reader :data
|
5
5
|
attr_reader :error_msg
|
6
|
-
attr_reader :success
|
7
6
|
attr_reader :cookies
|
7
|
+
attr_reader :status_code
|
8
|
+
attr_reader :success
|
8
9
|
alias_method :successful?, :success
|
9
10
|
|
10
11
|
def initialize(response, cookies=nil)
|
11
12
|
response = Map.new(response)
|
12
13
|
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
14
|
+
@status_code = response.delete(:status_code)
|
15
|
+
@success = response.delete(:success)
|
16
|
+
@error_msg = response.delete(:reason)
|
17
|
+
@data = response
|
18
|
+
@cookies = cookies
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
@@ -41,13 +41,22 @@ module SynapseClient
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.retrieve(access_token, refresh_token)
|
44
|
-
response =
|
44
|
+
response = Customer.get_user({
|
45
|
+
:access_token => access_token,
|
46
|
+
:refresh_token => refresh_token
|
47
|
+
})
|
48
|
+
|
49
|
+
unless response.successful? # refresh tokens & try once more.
|
50
|
+
new_tokens = Customer.refresh_tokens(access_token, refresh_token)
|
51
|
+
return new_tokens if new_tokens.instance_of?(SynapseClient::Error)
|
52
|
+
return Customer.get_user({
|
53
|
+
:access_token => new_tokens.access_token,
|
54
|
+
:refresh_token => new_tokens.refresh_token,
|
55
|
+
:expires_in => new_tokens.expires_in
|
56
|
+
})
|
57
|
+
end
|
45
58
|
|
46
|
-
|
47
|
-
Customer.new(response.data.user.merge({
|
48
|
-
:access_token => access_token,
|
49
|
-
:refresh_token => refresh_token
|
50
|
-
}))
|
59
|
+
response
|
51
60
|
end
|
52
61
|
|
53
62
|
# TODO
|
@@ -99,21 +108,30 @@ module SynapseClient
|
|
99
108
|
end
|
100
109
|
end
|
101
110
|
|
102
|
-
def refresh_tokens
|
111
|
+
def self.refresh_tokens(access_token, refresh_token)
|
103
112
|
rt = SynapseClient::RefreshedTokens.new({
|
104
|
-
:old_access_token =>
|
105
|
-
:old_refresh_token =>
|
113
|
+
:old_access_token => access_token,
|
114
|
+
:old_refresh_token => refresh_token
|
106
115
|
}).refresh_old_tokens
|
107
116
|
|
108
117
|
return rt if rt.instance_of?(SynapseClient::Error)
|
109
118
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
119
|
+
Map.new({
|
120
|
+
:access_token => rt.new_access_token,
|
121
|
+
:refresh_token => rt.new_refresh_token,
|
122
|
+
:expires_in => rt.new_expires_in
|
123
|
+
})
|
115
124
|
end
|
116
125
|
|
126
|
+
def self.get_user(opts={})
|
127
|
+
response = SynapseClient.request(:post, url + "show", {:access_token => opts[:access_token]})
|
128
|
+
|
129
|
+
return response unless response.successful?
|
130
|
+
|
131
|
+
opts.delete(:expires_in) if opts[:expires_in].nil?
|
132
|
+
|
133
|
+
Customer.new(response.data.user.merge(opts))
|
134
|
+
end
|
117
135
|
|
118
136
|
private
|
119
137
|
def update_attributes(data)
|
@@ -64,16 +64,32 @@ describe SynapseClient::Customer do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
-
describe "refreshing
|
67
|
+
describe "refreshing and retrieving customer" do
|
68
68
|
it "should successfully get new oauth consumer key, refresh token, and expires in." do
|
69
69
|
customer = SynapseClient::Customer.retrieve(@customer.access_token, @customer.refresh_token)
|
70
70
|
|
71
71
|
old_access_token = @customer.access_token.dup
|
72
72
|
old_refresh_token = @customer.refresh_token.dup
|
73
73
|
|
74
|
-
response =
|
74
|
+
response = SynapseClient::Customer.refresh_tokens(old_access_token, old_refresh_token)
|
75
75
|
|
76
|
-
expect(response).to be_a
|
76
|
+
expect(response).to be_a Map
|
77
|
+
|
78
|
+
expect(response.access_token).to be_a String
|
79
|
+
expect(response.refresh_token).to be_a String
|
80
|
+
expect(response.expires_in).to be_a Fixnum
|
81
|
+
|
82
|
+
expect(response.access_token).not_to be eq(old_access_token)
|
83
|
+
expect(response.refresh_token).not_to be eq(old_refresh_token)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should successfully retrieve a customer with a broken access token" do
|
87
|
+
old_access_token = @customer.access_token.dup
|
88
|
+
old_refresh_token = @customer.refresh_token.dup
|
89
|
+
|
90
|
+
customer = SynapseClient::Customer.retrieve("accexpired", @customer.refresh_token)
|
91
|
+
|
92
|
+
expect(customer).to be_a SynapseClient::Customer
|
77
93
|
|
78
94
|
expect(customer.access_token).to be_a String
|
79
95
|
expect(customer.refresh_token).to be_a String
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synapse_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Matthias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|