Skip to content

Commit

Permalink
Support for the UK REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
HashNotAdam committed Nov 14, 2019
1 parent 7e63caa commit 9277cf6
Show file tree
Hide file tree
Showing 116 changed files with 52,093 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ UK_CARD_EXTERNAL_ID='ABCDEFGHIJKLM123'

UK_REST_API_USERNAME='username'
UK_REST_API_PASSWORD='password'
UK_REST_API_MERCHANT_UNIQUE_TAG='tag'
UK_REST_API_PROGRAM_UNIQUE_TAG='tag'
UK_REST_API_MERCHANT_GROUP='tag'
UK_REST_API_PROGRAM='tag'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
coverage
Gemfile.lock
spec/examples.txt
spec/vcr_cassettes
16 changes: 16 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*

Metrics/BlockLength:
Exclude:
- spec/**/*

RSpec/BeforeAfterAll:
Enabled: false

Expand Down Expand Up @@ -58,6 +62,13 @@ Style/LambdaCall:
Style/NegatedIf:
Enabled: false

Style/OptionalArguments:
Exclude:
- lib/eml/error/**/*

Style/RaiseArgs:
Enabled: false

Style/Send:
Enabled: true

Expand All @@ -72,3 +83,8 @@ Style/TrailingCommaInArrayLiteral:

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrivialAccessors:
Exclude:
- lib/eml/uk/payload.rb
- lib/eml/uk/payload/**/*
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Declare your dependencies in eml.gemspec
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ require "eml"
EML::UK.configure do |config|
config.username = "username"
config.password = "password"
config.merchant = "merchant_id"
config.merchant_group = "merchant_id"
config.program = "program_id"
end
```
Expand Down
6 changes: 6 additions & 0 deletions eml.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ Gem::Specification.new do |s|
s.require_paths = ["lib"]

s.add_dependency "http", "~> 4.0.0"
s.add_dependency "sorbet-runtime"

s.add_development_dependency "dotenv"
s.add_development_dependency "faker"
s.add_development_dependency "pry-byebug"
s.add_development_dependency "rspec", "~> 3.8"
s.add_development_dependency "rubocop", "~> 0.71"
s.add_development_dependency "rubocop-performance"
s.add_development_dependency "rubocop-rspec"
s.add_development_dependency "simplecov"
s.add_development_dependency "sorbet"
s.add_development_dependency "vcr"
s.add_development_dependency "webmock"
end
20 changes: 16 additions & 4 deletions lib/eml.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# typed: strong
# frozen_string_literal: true

require "http"

require "eml/version"
require "eml/api_operations"
require "eml/uk"
require "sorbet-runtime"

module EML
end

require "eml/data/countries"
require "eml/data/currencies"
require "eml/data/states"

require "eml/config"
require "eml/environment"
require "eml/error"
require "eml/lib/endpoint_class"
require "eml/parameters"
require "eml/payload"
require "eml/response"
require "eml/uk"
require "eml/version"
11 changes: 0 additions & 11 deletions lib/eml/api_operation/create.rb

This file was deleted.

11 changes: 0 additions & 11 deletions lib/eml/api_operation/list.rb

This file was deleted.

16 changes: 0 additions & 16 deletions lib/eml/api_operation/request.rb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/eml/api_operations.rb

This file was deleted.

49 changes: 49 additions & 0 deletions lib/eml/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# typed: ignore
# frozen_string_literal: true

module EML
class Config
extend T::Sig

sig { returns(EML::Environment.class) }
def environment
EML::Environment
end

sig { params(value: Symbol).void }
def environment=(value)
EML::Environment.set(value)
end

sig { params(param: Symbol).returns(String) }
def require(param)
value = public_send(param)
return value unless value.nil? || value.empty?

require_error(param)
end

sig { params(param: Symbol).returns(String) }
def require_parameter(param)
require(param)
rescue ArgumentError => e
message = e.message + "\n" \
"Alternatively, you can pass dynamic values with your request " \
"parameters"
raise ArgumentError, message
end

private

sig { params(param: Symbol).void }
def require_error(param)
raise(
ArgumentError,
"#{param} is required but hasn't been set.\n" \
"EML::Config.configuration do |config|\n" +
%( config.#{param} = "value") + "\n" \
"end"
)
end
end
end
Loading

0 comments on commit 9277cf6

Please sign in to comment.