rally_up 1.0.1 → 1.0.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
  SHA256:
3
- metadata.gz: d974f1c002a3da939765394bec66b17a5789caa7095eaf654ee3c2faa583fcae
4
- data.tar.gz: 7685bddc6c797e99d2c31d1ee623c1234dda1face7bd09a71072fbe34b3431bb
3
+ metadata.gz: 66c3780b4fe79816f85ce27656dc8afd84ab81bf4737a378d7dc8937e9f26c84
4
+ data.tar.gz: 922850bada38ac2b5d336e7e019b3b6305cab593666821ea43bb5884aa20de07
5
5
  SHA512:
6
- metadata.gz: 66f5a4feb0846fb8b5787ad9cb265ac15c0126412dc4fa8be00b1dba6ceb0e1b21bb303f9e60de1d0c9b5474852761a370f837b7a51f87f02c310f1c55c60b1b
7
- data.tar.gz: cd7742fddb03fffc8f02a824ff778ed74915a64e55bfa04446b3608a4de590bac2f06934852ff07290fcb84df4cc960e881978df8f32d95a422a070bef797dae
6
+ metadata.gz: ab51745ce2e660233b48e5c43e93aa89bb04b48337e64092943e8d7b37fbb7f99a59d71bf6f71c16e9a47cedc54cd13eeb530d064c3e9531090315f3dc4b6146
7
+ data.tar.gz: 9ee18563c6c9d33df8ddd4061bad40e68017f739e723cae38187abbcebb018c915b1d5282d3e8b203c317e6357f2ef0b63d4b60c6ccde3a89efe37bb53dbc28f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rally_up (1.0.1)
4
+ rally_up (1.0.2)
5
5
  http (~> 4.0)
6
6
 
7
7
  GEM
@@ -49,7 +49,7 @@ GEM
49
49
  rspec-mocks (3.10.2)
50
50
  diff-lcs (>= 1.2.0, < 2.0)
51
51
  rspec-support (~> 3.10.0)
52
- rspec-support (3.10.2)
52
+ rspec-support (3.10.3)
53
53
  unf (0.1.4)
54
54
  unf_ext
55
55
  unf_ext (0.0.8)
@@ -70,4 +70,4 @@ DEPENDENCIES
70
70
  webmock
71
71
 
72
72
  BUNDLED WITH
73
- 2.2.26
73
+ 2.2.30
@@ -15,17 +15,27 @@ module RallyUp
15
15
  @expires = json[:'.expires']
16
16
  end
17
17
 
18
+ def expired?
19
+ expires.nil? || Time.parse(expires).utc < Time.now.utc
20
+ end
21
+
18
22
  class << self
19
23
  def retrieve(set: true)
20
- json = RallyUp::Partner.json(:post, '/v1/partnertoken', params: {
21
- grant_type: 'password',
22
- username: RallyUp::Partner.login,
23
- password: RallyUp::Partner.secret
24
- })
24
+ json = JSON.parse(access_token_response, symbolize_names: true)
25
25
  token = new(json)
26
- RallyUp::Partner.token = token.access_token if set
26
+ RallyUp::Partner.token = token if set
27
27
  token
28
28
  end
29
+
30
+ def access_token_response
31
+ params = {
32
+ grant_type: 'password',
33
+ username: RallyUp::Partner.login,
34
+ password: RallyUp::Partner.secret
35
+ }
36
+ HTTP.post("https://#{RallyUp::Partner.domain}/v1/partnertoken", body: URI.encode_www_form(params))
37
+ .body.to_s
38
+ end
29
39
  end
30
40
  end
31
41
  end
@@ -8,7 +8,7 @@ module RallyUp
8
8
  attr_accessor :login, :secret, :domain, :token
9
9
 
10
10
  def request(method, path, domain: RallyUp::Partner.domain, params: {}, headers: {})
11
- raise 'Missing RallyUp Partner Token' if RallyUp::Partner.nil?
11
+ set_token if RallyUp::Partner.token.nil? || RallyUp::Partner.token.expired?
12
12
 
13
13
  super(
14
14
  method,
@@ -16,11 +16,15 @@ module RallyUp
16
16
  domain: domain,
17
17
  params: params,
18
18
  headers: headers.merge(
19
- 'Authorization' => "Bearer #{RallyUp::Partner.token}",
19
+ 'Authorization' => "Bearer #{RallyUp::Partner.token.access_token}",
20
20
  'Content-Type' => 'application/x-www-form-urlencoded'
21
21
  )
22
22
  )
23
23
  end
24
+
25
+ def set_token
26
+ RallyUp::Partner::Token.retrieve(set: true)
27
+ end
24
28
  end
25
29
  end
26
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RallyUp
4
- VERSION = '1.0.1'
4
+ VERSION = '1.0.2'
5
5
  end
data/lib/rally_up.rb CHANGED
@@ -44,7 +44,7 @@ module RallyUp
44
44
  protected
45
45
 
46
46
  def verify!(response)
47
- return if response.code.to_i == 200
47
+ return if [200, 201].include?(response.code.to_i)
48
48
 
49
49
  raise Error, response
50
50
  end
@@ -56,11 +56,20 @@ module RallyUp
56
56
  def initialize(response)
57
57
  @body = response.body
58
58
  @code = response.code
59
+ super
59
60
  end
60
61
 
61
62
  def message
62
63
  "#{code} #{body}"
63
64
  end
65
+
66
+ def as_json
67
+ { error: to_s }
68
+ end
69
+
70
+ def to_s
71
+ "#{self.class}: #{message}"
72
+ end
64
73
  end
65
74
  end
66
75
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rally_up
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Richey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.0.3
118
+ rubygems_version: 3.2.15
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: RallyUp API & Partner API ruby gem