Skip to content

Commit

Permalink
Initial project skeleton including DotEnv, Rspec, Rubocop, VCR
Browse files Browse the repository at this point in the history
  • Loading branch information
HashNotAdam committed Sep 7, 2019
0 parents commit 7e63caa
Show file tree
Hide file tree
Showing 23 changed files with 486 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# see http://editorconfig.org/

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
insert_final_newline = true
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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'
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
coverage
Gemfile.lock
spec/vcr_cassettes
5 changes: 5 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
--color
--fail-fast
--format documentation
--profile
--require spec_helper
74 changes: 74 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require:
- rubocop-performance
- rubocop-rspec

AllCops:
TargetRubyVersion: 2.6.4

Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation

Layout/DotPosition:
EnforcedStyle: trailing

Layout/EndAlignment:
AutoCorrect: true
EnforcedStyleAlignWith: variable

Layout/IndentFirstArrayElement:
EnforcedStyle: consistent

Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

Layout/MultilineOperationIndentation:
EnforcedStyle: indented

Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*

RSpec/BeforeAfterAll:
Enabled: false

RSpec/ExampleLength:
Max: 10

RSpec/MultipleExpectations:
Enabled: false

RSpec/NestedGroups:
Max: 4

RSpec/FilePath:
Enabled: false

Security/Eval:
Enabled: false

Style/Documentation:
Enabled: false

Style/GuardClause:
Enabled: false

Style/LambdaCall:
Enabled: false

Style/NegatedIf:
Enabled: false

Style/Send:
Enabled: true

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
EnforcedStyle: double_quotes

Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: consistent_comma
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true
source "https://rubygems.org"

# Declare your dependencies in eml.gemspec
gemspec
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2019- Morning Coffee Pty Ltd (https://morningcoffee.com.au)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
87 changes: 87 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# EML API integration library for Ruby

The EML API integration library provides convenient access to EML's REST Web
Services and Transaction Notification Service for applications written in
the Ruby language.

Version 1 supports the UK APIs with Australian support coming as existing code
is extracted.

## Installation

You don't need this source code unless you want to modify the gem. If you just
want to use the package, just include the following in your Gemfile:

```sh
gem "eml", github: "MorningCoffeeDev/eml_ruby"
```

If you are debugging or developing this gem and wish to use it within the
context of an existing application, modify your Gemfile to read:

```sh
gem "eml", path: "../path_to_gem"
```

### Requirements

- Ruby 2.6+ (untested in prior versions)

## Usage

Each geographical region is a separate module and will need to be configured
with your supplied credentials.

```ruby
require "eml"

EML::UK.configure do |config|
config.username = "username"
config.password = "password"
config.merchant = "merchant_id"
config.program = "program_id"
end
```

Make sure you never commit your credentials to git. If you are using Ruby on
Rails, it is usually best to keep your secrets in your
[credentials file]: https://edgeguides.rubyonrails.org/security.html#custom-credentials

## Development

Since it is necessary to authenticate with EML to test API resources,
credentials and a test card ID are required. The dotenv gem is loaded when tests
are run and will look for a .env file in the root directory. A .env.example file
has been supplied so you copy it to .env and replace the example values:

```sh
cp .env.example .env
```

The .env file has been added to the .gitignore list and should never been
commited to the repository.

Run all tests:

```sh
bundle exec rspec
```

Run a single test suite:

```sh
bundle exec rspec spec/path/to/file.rb
```

Run a single test, include the line number:

```sh
bundle exec rspec spec/path/to/file.rb:123
```

Please ensure that all changes have been run by the Rubocop before creating a
pull request:

```sh
bundle exec rubocop
```
31 changes: 31 additions & 0 deletions eml.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

$LOAD_PATH.unshift(::File.join(::File.dirname(__FILE__), "lib"))

require "eml/version"

Gem::Specification.new do |s|
s.name = "eml"
s.version = EML::VERSION
s.required_ruby_version = ">= 2.6.0"
s.summary = "Ruby bindings for the EML API"
s.description = "Connect to the EML payments APIs and " \
"Transaction Notification Serices"
s.author = "Morning Coffee"
s.email = "[email protected]"
s.homepage = "https://github.com/MorningCoffeeDev/eml_ruby"
s.license = "MIT"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- test/*`.split("\n")
s.require_paths = ["lib"]

s.add_dependency "http", "~> 4.0.0"

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 "vcr"
end
10 changes: 10 additions & 0 deletions lib/eml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "http"

require "eml/version"
require "eml/api_operations"
require "eml/uk"

module EML
end
11 changes: 11 additions & 0 deletions lib/eml/api_operation/create.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module EML
module APIOperation
module Create
def create(params = {})
request(:post, resource_url, params)
end
end
end
end
11 changes: 11 additions & 0 deletions lib/eml/api_operation/list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module EML
module APIOperation
module List
def list(filters = {})
request(:get, resource_url, filters)
end
end
end
end
16 changes: 16 additions & 0 deletions lib/eml/api_operation/request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module EML
module APIOperation
module Request
module ClassMethods
def request(method, url, params = {})
end
end

def self.included(base)
base.extend(ClassMethods)
end
end
end
end
4 changes: 4 additions & 0 deletions lib/eml/api_operations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# frozen_string_literal: true

require "eml/api_operation/create"
require "eml/api_operation/request"
14 changes: 14 additions & 0 deletions lib/eml/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

require "eml/error/rest"

module EML
# Error is the base class for more specific EML errors
class Error
attr_reader :message

def initialize(message = nil)
@message = message
end
end
end
6 changes: 6 additions & 0 deletions lib/eml/error/rest/authentication.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

module EML
class AuthenticationError < Error
end
end
10 changes: 10 additions & 0 deletions lib/eml/uk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

require "eml/uk/api_resource"
require "eml/uk/config"
require "eml/uk/resources"

module EML
module UK
end
end
13 changes: 13 additions & 0 deletions lib/eml/uk/api_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module EML
class APIResource
def resource_url
if id.present?
"#{self::ENDPOINT_BASE}/#{id}"
else
self::ENDPOINT_BASE
end
end
end
end
22 changes: 22 additions & 0 deletions lib/eml/uk/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module EML
module UK
class << self
def configure
yield config
end

def config
@config ||= Config.new
end
end

class Config
attr_accessor :username
attr_accessor :password
attr_accessor :merchant
attr_accessor :program
end
end
end
3 changes: 3 additions & 0 deletions lib/eml/uk/resources.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require "eml/uk/resources/card"
5 changes: 5 additions & 0 deletions lib/eml/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module EML
VERSION = "0.0.1"
end
Loading

0 comments on commit 7e63caa

Please sign in to comment.