whiplash-app 0.8.1 → 0.9.0

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: f264f95fe30e26b24988d6f8db597a349259a79ab9fb446402a3528569112fed
4
- data.tar.gz: a07d6c73760ec2d98107b0510c7f7d9b3566a217afe364b2b53e9044eebe940f
3
+ metadata.gz: 38965dd5a29730aa36f70c5b685aa575aef968b6b6fb8f81efd4e4defb6c8b56
4
+ data.tar.gz: 0d42efa6c4d541f49d8fcc0b67d09e06ab25dc585fe4abf9c0ac8058c1ddf24c
5
5
  SHA512:
6
- metadata.gz: 34d77d907ea7d03b60483b3fd7f6177e1a9c1d502cef48e27bccc77c8694849ded0a47e9f1155025602c4dcadb78af0753502e0ab46305ad7f411caa32a992ca
7
- data.tar.gz: 356479891eb004b6beb00437452ed0b55190176618aff587fb3d5d9370c8689673a2388d1c6ae08e69f4c6472f8c0e134f910e152706aa8e04ac0c6e36143dc3
6
+ metadata.gz: e2a65da32cf144d8e5c22f6c4efce8f9b3109cb484398bdb65ad4a17fb3a3b4ae85b9a29d28919055e0a597d16fd907dea9847ff8054e5bb5c353c9877f1433a
7
+ data.tar.gz: 3b7c40b3da5a6bb4dd3e7bf4e4fd9e1c29587f870853c3c8df3f706d2aa35e030151de3759abc1c6170deb7af92e443a4377e4761f9a4851f7b607259c64fbbd
@@ -0,0 +1,41 @@
1
+ name: "Whiplash App CI Workflow"
2
+ on:
3
+ pull_request_target:
4
+ types: [opened, synchronize, reopened]
5
+ workflow_dispatch:
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - name: Checkout code
13
+ uses: actions/checkout@v3
14
+ with:
15
+ ref: ${{ github.event.pull_request.head.sha }}
16
+
17
+ - name: Install ruby and gems
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: '2.6.7'
21
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
22
+
23
+ - run: gem install bundler -v 2.2.25
24
+
25
+ - run: bundle exec rake
26
+
27
+ - name: Slack Notification
28
+ uses: 8398a7/action-slack@v3
29
+ with:
30
+ status: ${{ job.status }}
31
+ fields: repo,message,pullRequest,author
32
+ custom_payload: |
33
+ {
34
+ attachments: [{
35
+ color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
36
+ text: `${process.env.AS_WORKFLOW}\n${process.env.AS_JOB} for (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
37
+ }]
38
+ }
39
+ env:
40
+ SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}}
41
+ if: always() #Pick up events even if the job fails or is canceled.
@@ -45,16 +45,16 @@ module Whiplash
45
45
  case e.message
46
46
  when 'end of file reached'
47
47
  store_whiplash_error!(:eof, options)
48
- Rails.logger.error "[Whiplash][EOF] Failed to connect to #{url}"
49
- raise ProviderError::InternalServerError, e.message
48
+ Rails.logger.error "[Whiplash][EOF] Failed to connect with options: #{options.inspect}"
49
+ raise WhiplashApiError::InternalServerError, e.message
50
50
  when 'Net::OpenTimeout'
51
51
  store_whiplash_error!(:timeout, options)
52
- Rails.logger.error "[Whiplash][Timeout] Request to #{url} timed out"
53
- raise ProviderError::Timeout, e.message
52
+ Rails.logger.error "[Whiplash][Timeout] Request with options: #{options.inspect} timed out"
53
+ raise WhiplashApiError::Timeout, e.message
54
54
  else
55
55
  store_whiplash_error!(:connection, options)
56
- Rails.logger.error "[Whiplash] Request to #{url} failed"
57
- raise ProviderError::InternalServerError, e.message
56
+ Rails.logger.error "[Whiplash] Request with options: #{options.inspect} failed"
57
+ raise WhiplashApiError::InternalServerError, e.message
58
58
  end
59
59
  end
60
60
  end
@@ -161,7 +161,8 @@ module Whiplash
161
161
  if !response.success?
162
162
  case response.status
163
163
  when 500
164
- Appsignal.send_error(WhiplashApiError::InternalServerError.new(response.body), {raised: false})
164
+ # Do we want to replace this with anything?
165
+ # Appsignal.send_error(WhiplashApiError::InternalServerError.new(response.body), {raised: false})
165
166
  else
166
167
  end
167
168
 
@@ -1,5 +1,5 @@
1
1
  module Whiplash
2
2
  class App
3
- VERSION = "0.8.1"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
data/lib/whiplash/app.rb CHANGED
@@ -1,37 +1,28 @@
1
1
  require "whiplash/app/api_config"
2
- require "whiplash/app/caching"
3
2
  require "whiplash/app/connections"
4
3
  require "whiplash/app/finder_methods"
5
4
  require "whiplash/app/signing"
6
5
  require "whiplash/app/version"
7
6
  require "errors/whiplash_api_error"
8
7
  require "oauth2"
9
- require "faraday_middleware"
8
+ require "faraday"
10
9
 
11
10
  module Whiplash
12
11
  class App
13
12
  include Whiplash::App::ApiConfig
14
- include Whiplash::App::Caching
15
13
  include Whiplash::App::Connections
16
14
  include Whiplash::App::FinderMethods
17
15
  extend Whiplash::App::Signing
18
16
 
19
17
  attr_accessor :customer_id, :shop_id, :token
20
18
 
21
- def initialize(token=nil, options={})
22
- token ||= cache_store["whiplash_api_token"]
23
- @token = format_token(token) unless token.nil?
19
+ def initialize(token, options={})
20
+ @token = format_token(token)
24
21
  @customer_id = options[:customer_id]
25
22
  @shop_id = options[:shop_id]
26
23
  @api_version = options[:api_version] || 2 # can be 2_1
27
24
  end
28
25
 
29
- def self.whiplash_api_token
30
- store = Moneta.new(:Redis, host: ENV["REDIS_HOST"], port: ENV["REDIS_PORT"], password: ENV["REDIS_PASSWORD"], expires: 7200)
31
- cache_store = Moneta::Namespace.new store, Whiplash::App::Caching.namespace_value
32
- cache_store["whiplash_api_token"]
33
- end
34
-
35
26
  def client
36
27
  OAuth2::Client.new(ENV["WHIPLASH_CLIENT_ID"], ENV["WHIPLASH_CLIENT_SECRET"], site: api_url)
37
28
  end
@@ -41,14 +32,11 @@ module Whiplash
41
32
  end
42
33
 
43
34
  def connection
44
- out = Faraday.new [api_url, versioned_api_url].join("/") do |conn|
45
- conn.request :oauth2, token.token, token_type: "bearer"
35
+ Faraday.new [api_url, versioned_api_url].join("/") do |conn|
36
+ conn.request :authorization, 'Bearer', token.token
46
37
  conn.request :json
47
38
  conn.response :json, :content_type => /\bjson$/
48
- conn.use :instrumentation
49
- conn.adapter Faraday.default_adapter
50
39
  end
51
- return out
52
40
  end
53
41
 
54
42
  def token=(oauth_token)
@@ -60,8 +48,6 @@ module Whiplash
60
48
  when /app_(manage|read)/
61
49
  begin
62
50
  access_token = client.client_credentials.get_token(scope: ENV["WHIPLASH_CLIENT_SCOPE"])
63
- new_token = access_token.to_hash
64
- cache_store["whiplash_api_token"] = new_token
65
51
  rescue URI::InvalidURIError => e
66
52
  raise StandardError, "The provide URL (#{ENV["WHIPLASH_API_URL"]}) is not valid"
67
53
  end
@@ -75,9 +61,6 @@ module Whiplash
75
61
 
76
62
  def token_expired?
77
63
  return token.expired? unless token.nil?
78
- return true unless cache_store.key?("whiplash_api_token")
79
- return true if cache_store["whiplash_api_token"].nil?
80
- return true if cache_store["whiplash_api_token"].empty?
81
64
  false
82
65
  end
83
66
 
data/whiplash-app.gemspec CHANGED
@@ -19,8 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "oauth2", "~> 2.0.4"
22
- spec.add_dependency "faraday_middleware", "~> 1.2.0"
23
- spec.add_dependency "moneta", "~> 0.8.0"
22
+ spec.add_dependency "faraday", "~> 2.7"
24
23
 
25
24
  spec.add_development_dependency "bundler", ">= 2.2"
26
25
  spec.add_development_dependency "rake", ">= 12.3.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whiplash-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Don Sullivan, Mark Dickson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-29 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oauth2
@@ -25,33 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.0.4
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
28
+ name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.0
33
+ version: '2.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.0
41
- - !ruby/object:Gem::Dependency
42
- name: moneta
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: 0.8.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: 0.8.0
40
+ version: '2.7'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: bundler
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +102,7 @@ executables: []
116
102
  extensions: []
117
103
  extra_rdoc_files: []
118
104
  files:
105
+ - ".github/workflows/ci.yml"
119
106
  - ".gitignore"
120
107
  - ".idea/.gitignore"
121
108
  - ".rspec"
@@ -128,10 +115,8 @@ files:
128
115
  - lib/errors/whiplash_api_error.rb
129
116
  - lib/whiplash/app.rb
130
117
  - lib/whiplash/app/api_config.rb
131
- - lib/whiplash/app/caching.rb
132
118
  - lib/whiplash/app/connections.rb
133
119
  - lib/whiplash/app/finder_methods.rb
134
- - lib/whiplash/app/moneta/namespace.rb
135
120
  - lib/whiplash/app/signing.rb
136
121
  - lib/whiplash/app/version.rb
137
122
  - whiplash-app.gemspec
@@ -153,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
138
  - !ruby/object:Gem::Version
154
139
  version: '0'
155
140
  requirements: []
156
- rubygems_version: 3.0.9
141
+ rubygems_version: 3.4.10
157
142
  signing_key:
158
143
  specification_version: 4
159
144
  summary: this gem provides connectivity to the Whiplash API for authentication and
@@ -1,22 +0,0 @@
1
- require "moneta"
2
- require "whiplash/app/moneta/namespace"
3
- module Whiplash
4
- class App
5
- module Caching
6
-
7
- def cache_store
8
- if ENV["REDIS_HOST"]
9
- store = Moneta.new(:Redis, host: ENV["REDIS_HOST"], port: ENV["REDIS_PORT"], password: ENV["REDIS_PASSWORD"], expires: 7200)
10
- Moneta::Namespace.new store, Whiplash::App::Caching.namespace_value
11
- else
12
- Moneta.new(:File, dir: "tmp", expires: 7200)
13
- end
14
- end
15
-
16
- def self.namespace_value
17
- ENV["REDIS_NAMESPACE"] || ENV["WHIPLASH_CLIENT_ID"]
18
- end
19
-
20
- end
21
- end
22
- end
@@ -1,45 +0,0 @@
1
- module Moneta
2
- class Namespace
3
- attr_reader :moneta_store
4
-
5
- def initialize store, ns
6
- @moneta_store, @ns = store, ns
7
- end
8
-
9
- def [] key
10
- @moneta_store["#{@ns}:#{key}"]
11
- end
12
-
13
- def []= key, value
14
- @moneta_store["#{@ns}:#{key}"] = value
15
- end
16
-
17
- def delete key
18
- @moneta_store.delete "#{@ns}:#{key}"
19
- end
20
-
21
- def key? key
22
- @moneta_store.key? "#{@ns}:#{key}"
23
- end
24
-
25
- def has_key? key
26
- @moneta_store.has_key? "#{@ns}:#{key}"
27
- end
28
-
29
- def store key, value, options
30
- @moneta_store.store "#{@ns}:#{key}", value, options
31
- end
32
-
33
- def update_key key, options
34
- @moneta_store.update_key "#{@ns}:#{key}", options
35
- end
36
-
37
- def clear
38
- @moneta_store.clear
39
- end
40
-
41
- def method_missing method, args
42
- @moneta_store.call method, *args
43
- end
44
- end
45
- end