act_as_api_client 0.1.2 → 0.2.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: 13860c59da96b02912087fdca87e607dcd3dd06ad8f3e530512deaa955aedd2c
4
- data.tar.gz: 8d88e51474d2df43bb768a225d883c43ef962d16d38555097e644d6a95b07de4
3
+ metadata.gz: 585bfe652e889c7eaebcd2dfefd0a0c295ae87a390f9522de24fc2126e9011b3
4
+ data.tar.gz: 5d61e33b3f9702b1bbcc2bac97913278dcbcfc6e7db780e0ea4b1a1efdfb14cb
5
5
  SHA512:
6
- metadata.gz: '0924a1f702f7da3172d4d00a0a5489b2c1973e29f3322b3b7a9fd38b1746fe8972c10cca4e9b4d47a0ffe729f8e3eba818b707fcad9347c344364a2e202b5994'
7
- data.tar.gz: 2caeec1dfddd4ede8aabb0de72949f14812087cbdc53404397baf83c4a7cd810aede6cf3796d99f5b7d093bf8ca31011cb206fe470c7aff28dd4394a364d5e85
6
+ metadata.gz: e2cc7b10a33b1d6955b6aad98709aa58ddba78e38e7804ab6f8b4b8be49ce4ac4b93077cdfa0a9f81e6ea5501784ce02d0ff278228affb4a33a23d71ed52adbe
7
+ data.tar.gz: c3926de463c5fef33ce98c7158165cffe8fb19d5eef4a94b72fc14fbc51b9a0966134845d899a23310e26b786326a1fe9ee1f058390f7c19809efefa43f7b822
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
- # on 2022-07-11 09:13:33 UTC using RuboCop version 0.93.1.
3
+ # on 2022-07-28 12:30:04 UTC using RuboCop version 0.93.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
@@ -12,12 +12,13 @@ Metrics/AbcSize:
12
12
  Exclude:
13
13
  - 'lib/act_as_api_client/clients/github_client.rb'
14
14
 
15
- # Offense count: 4
15
+ # Offense count: 5
16
16
  # Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods.
17
17
  # ExcludedMethods: refine
18
18
  Metrics/BlockLength:
19
19
  Exclude:
20
20
  - '**/*.gemspec'
21
+ - 'spec/act_as_api_client/clients/authorize_net/authorize_net_notifications_client_spec.rb'
21
22
  - 'spec/act_as_api_client/clients/github_client/find_by_spec.rb'
22
23
  - 'spec/act_as_api_client/clients/github_client/find_spec.rb'
23
24
  - 'spec/act_as_api_client/clients/github_client/where_spec.rb'
@@ -46,6 +47,13 @@ RSpec/ExampleLength:
46
47
  Exclude:
47
48
  - 'spec/act_as_api_client/clients/http_client_spec.rb'
48
49
 
50
+ # Offense count: 2
51
+ # Configuration parameters: CustomTransform, IgnoreMethods, SpecSuffixOnly.
52
+ RSpec/FilePath:
53
+ Exclude:
54
+ - 'spec/act_as_api_client/clients/authorize_net/authorize_net_notifications_client_spec.rb'
55
+ - 'spec/act_as_api_client/clients/authorize_net/authorize_net_webhooks_client_spec.rb'
56
+
49
57
  # Offense count: 3
50
58
  # Configuration parameters: Max.
51
59
  RSpec/NestedGroups:
@@ -53,9 +61,16 @@ RSpec/NestedGroups:
53
61
  - 'spec/act_as_api_client/clients/github_client/find_by_spec.rb'
54
62
 
55
63
  # Offense count: 1
64
+ # Configuration parameters: MinBodyLength.
65
+ Style/GuardClause:
66
+ Exclude:
67
+ - 'lib/act_as_api_client/clients/authorize_net_webhooks_client.rb'
68
+
69
+ # Offense count: 4
56
70
  # Cop supports --auto-correct.
57
71
  # Configuration parameters: AutoCorrect, Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
58
72
  # URISchemes: http, https
59
73
  Layout/LineLength:
60
74
  Exclude:
61
75
  - 'lib/act_as_api_client/clients/github_client.rb'
76
+ - 'spec/support/vcr_setup.rb'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- act_as_api_client (0.1.1)
4
+ act_as_api_client (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -44,7 +44,7 @@ GEM
44
44
  rubocop-ast (>= 0.6.0)
45
45
  ruby-progressbar (~> 1.7)
46
46
  unicode-display_width (>= 1.4.0, < 2.0)
47
- rubocop-ast (1.18.0)
47
+ rubocop-ast (1.19.1)
48
48
  parser (>= 3.1.1.0)
49
49
  rubocop-rspec (1.44.1)
50
50
  rubocop (~> 0.87)
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "http_client"
4
+ require_relative "./authorize_net_webhooks_client"
5
+ require "base64"
6
+
7
+ module ActAsApiClient
8
+ module Clients
9
+ module AuthorizeNetNotificationsClient
10
+ include AuthorizeNetWebhooksClient
11
+
12
+ def where(parameters = {})
13
+ # GET https://apitest.authorize.net/rest/v1/notifications?from_date=2017-03-01&to_date=2017-03-13&offset=0&limit=100
14
+ # GET https://apitest.authorize.net/rest/v1/notifications?deliveryStatus=Failed
15
+ # [:from_date, :to_date, :offset, :limit, :deliveryStatus]
16
+
17
+ get("https://#{base_uri}/rest/v1/notifications/",
18
+ headers: { "Authorization" => auth },
19
+ params: parameters)
20
+ end
21
+
22
+ def find(uuid)
23
+ raise StandardError, "uuid is not provided" if uuid.empty?
24
+
25
+ get("https://#{base_uri}/rest/v1/notifications/#{uuid}",
26
+ headers: { "Authorization" => auth })
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "http_client"
4
+ require "base64"
5
+
6
+ module ActAsApiClient
7
+ module Clients
8
+ module AuthorizeNetWebhooksClient
9
+ include HttpClient
10
+ DEFAULT_OPTIONS = {
11
+ mode: :production
12
+ }.freeze
13
+
14
+ def initialize
15
+ @options = DEFAULT_OPTIONS.merge(options)
16
+ end
17
+
18
+ def find(uuid)
19
+ raise StandardError, "uuid is not provided" if uuid.empty?
20
+
21
+ get("https://#{base_uri}/rest/v1/webhooks/#{uuid}",
22
+ headers: { "Authorization" => auth })
23
+ end
24
+
25
+ private
26
+
27
+ def base_uri
28
+ if @options[:mode] == :test
29
+ "apitest.authorize.net"
30
+ else
31
+ "authorize.net"
32
+ end
33
+ end
34
+
35
+ def auth
36
+ if options[:payment_user]
37
+ "Basic #{Base64.strict_encode64("#{options[:payment_user]}:#{options[:payment_pass]}")}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -23,7 +23,7 @@ module ActAsApiClient
23
23
  end
24
24
 
25
25
  case response
26
- when Net::HTTPNotFound, Net::HTTPSuccess, Net::HTTPUnprocessableEntity
26
+ when Net::HTTPNotFound, Net::HTTPSuccess, Net::HTTPUnprocessableEntity, Net::HTTPUnauthorized
27
27
  ::JSON.parse(response.body)
28
28
  end
29
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActAsApiClient
4
- VERSION = "0.1.2"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -17,13 +17,26 @@ class ApiClient
17
17
  def set_general_client(client_for:)
18
18
  return if client_for.nil?
19
19
 
20
+ class_name = convert_underscore_to_camelcase(client_for)
21
+
20
22
  require(File.expand_path("act_as_api_client/clients/#{client_for}_client",
21
23
  File.dirname(__FILE__)))
22
- include const_get("ActAsApiClient::Clients::#{client_for.capitalize}Client")
24
+ include const_get("ActAsApiClient::Clients::#{class_name}Client")
23
25
  end
24
26
 
25
27
  def set_options(options:)
26
28
  define_method("options") { options }
27
29
  end
30
+
31
+ # Converting from authorize_net_webhooks_client to AuthorizeNetWebhooksClient
32
+ #
33
+ # @param value [String] string with underscores
34
+ #
35
+ # @return [String] transformed in camel case format string
36
+ def convert_underscore_to_camelcase(value)
37
+ value.to_s.capitalize.gsub(/_(.)/) do |s|
38
+ s.upcase.gsub("_", "")
39
+ end
40
+ end
28
41
  end
29
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: act_as_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Rukomoynikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-17 00:00:00.000000000 Z
11
+ date: 2022-07-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Helps you to build reliable API clients in a minute. Just add act_as_api_client
14
14
  to your classes
@@ -35,6 +35,8 @@ files:
35
35
  - demo.rb
36
36
  - lib/act_as_api_client.rb
37
37
  - lib/act_as_api_client/base_api_methods.rb
38
+ - lib/act_as_api_client/clients/authorize_net_notifications_client.rb
39
+ - lib/act_as_api_client/clients/authorize_net_webhooks_client.rb
38
40
  - lib/act_as_api_client/clients/github_client.rb
39
41
  - lib/act_as_api_client/clients/http_client.rb
40
42
  - lib/act_as_api_client/version.rb