rtx-api 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ef858f06474a8ee43054c1bac8a2f1bf0160e85a
4
- data.tar.gz: ff3bb4d926d1c022e1c58ce68dea4db927b3d492
3
+ metadata.gz: 3e8e770ba4720010d7e1b230e02327da4a26b0da
4
+ data.tar.gz: 49141abf05dc7227b67d7469f4cc8ad32970a603
5
5
  SHA512:
6
- metadata.gz: 852439157ffad8652b595a10d2d097b027c7f0665ae111b7865c43417dbaf8601f66b832484ce13570b66e5d35b50a831e53e5924df5003c0b1a542f3a3f050d
7
- data.tar.gz: 26f571423e1c8f1e02500eee43b6afb2bf745516a20ed9496ff270e7633175e5db7d843c5ab333a6cb4020d9234c1d0217e827f67095ecef95eb1e9b22ec78f3
6
+ metadata.gz: f0a2083bb4061e976d501a742ed33fc0b392e3ce2cf366e081de77599132b61f412720ed9cd1de95cbe46b9ea355d7384522c54b7d3603d9459c00a9ca469c87
7
+ data.tar.gz: 3e15cce436dae73c010af01792146f24ab475e2eb35bf4b939586d9ea7a8d9f1d93b3a78dc9d8bd4369f284b6736186dabf27302718a6523008cfce40c170204
@@ -21,10 +21,22 @@ module RTX
21
21
  if request.code != 201
22
22
  raise API::Errors::AuthenticationError.new("Authentication Login Error: #{response}")
23
23
  end
24
- @token = response[:token]
25
- @expires = response[:expires_at]
26
- @account_id = response[:account_id]
27
- @profile_id = response[:profile_id]
24
+ set_attributes(response[:token], response[:expires_at], response[:account_id], response[:profile_id])
25
+ end
26
+
27
+ def authenticate_as(email, &block)
28
+ authenticate if !authenticated?
29
+ response = collection(:users, email: email)
30
+ if response[:_total] == 1
31
+ user = response[:_embedded][:users][0]
32
+ auth_response = post(:auth_tokens, account_id: user[:account_id], user_id: user[:id])
33
+ client = self.class.new(auth_response[:email], auth_response[:token])
34
+ client.set_attributes(auth_response[:token], auth_response[:expires_at], auth_response[:account_id], auth_response[:profile_id])
35
+ block.call(client)
36
+ else
37
+ raise API::Errors::ClientError.new("User not found with associated email address: #{email}")
38
+ end
39
+ true
28
40
  end
29
41
 
30
42
  def expired?
@@ -105,12 +117,19 @@ module RTX
105
117
  path
106
118
  end
107
119
 
120
+ def set_attributes(token, expires, account_id, profile_id)
121
+ @token = token
122
+ @expires = expires
123
+ @account_id = account_id
124
+ @profile_id = profile_id
125
+ end
126
+
108
127
  protected
109
128
 
110
129
  def default_headers
111
130
  {
112
- 'Content-Type' => "application/vnd.rtx.v2.hal+json",
113
- 'Accept' => "application/vnd.rtx.v2.hal+json",
131
+ 'Content-Type' => "application/hal+json",
132
+ 'Accept' => "application/hal+json",
114
133
  'User-Agent' => "rtx-api-client-ruby/#{API::VERSION}"
115
134
  }.freeze
116
135
  end
@@ -7,6 +7,7 @@ module RTX
7
7
  alerts: 'alerts',
8
8
  alert_frequencies: 'alert_frequencies',
9
9
  alert_types: 'alert_types',
10
+ auth_tokens: 'auth/tokens',
10
11
  campaigns: 'campaigns',
11
12
  contacts: 'contacts',
12
13
  countries: 'countries',
@@ -1,5 +1,5 @@
1
1
  module RTX
2
2
  module API
3
- VERSION = "0.3.1"
3
+ VERSION = "0.3.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtx-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ReviewTrackers Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty