dannysmith_coolpay 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 02e7d7194f5e7ce5e13984ea0019452f92c9ec92
4
+ data.tar.gz: 84f0f6790ba8f87467803ec61711e83daaa2e735
5
+ SHA512:
6
+ metadata.gz: 94bfb32fd22072f69a96c0985598c5ce65661d36636714184d39ea49282c015e902cd08b1ec3419155b6170aa195a877f5294cad45491edf2489a4377b36ad16
7
+ data.tar.gz: 4156009a45ad05ae851ec0c7152cbcd7e7b24b6a52c30316323908ad9ad14ca65e908c88a08740253f7636764016b0d05740399832ca2a1a6026ce480915bcfa
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .tags
11
+ .tags1
12
+ .env
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hi@danny.is. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coolpay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Danny Smith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Coolpay Wrapper Gem
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'dannysmith_coolpay'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself with:
16
+
17
+ $ gem install dannysmith_coolpay
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ c = Connection.new username: 'username',
23
+ api_key: 'ABC123',
24
+ api_endpoint_url: 'https://coolpay.herokuapp.com/api'
25
+
26
+ c.create_recipient name: 'Joe Bloggs' #=> <Recipient>
27
+ c.recipients #=> List of all recipients
28
+
29
+ # Making a payment
30
+ lucky_winner = c.recipients(name: 'Joe Bloggs').first
31
+
32
+ c.create_payment amount: '1000.00',
33
+ currency: 'GBP',
34
+ recipient_id: lucky_winner.id
35
+
36
+ c.payments #=> List of all payments
37
+ ```
38
+
39
+ ## To run the tests
40
+
41
+ Set three environment variables:
42
+
43
+ ```
44
+ COOLPAY_USERNAME=mrbloggs
45
+ COOLPAY_API_KEY=ABC12345678
46
+ COOLPAY_API_ENDPOINT_URL=https://coolpay.herokuapp.com/api
47
+ ```
48
+
49
+ Then run `rake spec`.
50
+
51
+ ## Stuff this should have in it if it wasn't an exercise
52
+
53
+ * [ ] Cleaner tests.
54
+ * [ ] More sensible tests for `Connection#payments` and `Connection#recipients`.
55
+ * [ ] A way of reauthorizing, in case the tokens time out.
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'coolpay'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/coolpay.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'coolpay/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'dannysmith_coolpay'
9
+ spec.version = Coolpay::VERSION
10
+ spec.authors = ['Danny Smith']
11
+ spec.email = ['hi@danny.is']
12
+
13
+ spec.summary = 'Gem to wrap the Coolpay API.'
14
+ spec.description = 'Gem to wrap the Coolpay API.'
15
+ spec.homepage = 'http://github.com/dannysmith/coolpay'
16
+ spec.license = 'MIT'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = 'exe'
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.14'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.0'
28
+ spec.add_development_dependency 'vcr'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'awesome_print'
31
+ spec.add_development_dependency 'pry'
32
+ spec.add_development_dependency 'pry-doc'
33
+
34
+ spec.add_dependency 'httparty'
35
+ spec.add_dependency 'json'
36
+ end
@@ -0,0 +1,95 @@
1
+ module Coolpay
2
+ class Connection
3
+ attr_accessor :api_endpoint_url, :username, :api_key, :token
4
+
5
+ def initialize(username:, api_key:, api_endpoint_url:nil)
6
+ raise InvalidConnection, 'You must specify an API endpoint' if api_endpoint_url.nil?
7
+ @api_endpoint_url = api_endpoint_url
8
+ @username = username
9
+ @api_key = api_key
10
+ authenticate!
11
+ end
12
+
13
+ def create_recipient(name:)
14
+ res = call_api '/recipients', method: :post, body: {recipient: {name: name}}
15
+ if res.code == 201
16
+ Recipient.new(name: res['recipient']['name'], id: res['recipient']['id'])
17
+ end
18
+ end
19
+
20
+ def recipients(name: nil)
21
+ if name
22
+ res = call_api '/recipients', method: :get, query: {name: name}
23
+ else
24
+ res = call_api '/recipients', method: :get
25
+ end
26
+
27
+ if res.code == 200
28
+ res['recipients'].map{ |r| Recipient.new(name: r['name'], id: r['id']) }
29
+ end
30
+ end
31
+
32
+ def create_payment(amount:, recipient_id:, currency: 'GBP')
33
+ res = call_api '/payments', method: :post, body: {
34
+ payment: {amount: amount, recipient_id: recipient_id, currency: currency}
35
+ }
36
+ if res.code == 201
37
+ Payment.new(
38
+ amount: res['payment']['amount'],
39
+ recipient_id: res['payment']['recipient_id'],
40
+ id: res['payment']['id'],
41
+ currency: res['payment']['currency'],
42
+ status: res['payment']['status']
43
+ )
44
+ end
45
+ end
46
+
47
+ def payments
48
+ res = call_api '/payments', method: :get
49
+ if res.code == 200
50
+ res['payments'].map{ |r| Payment.new(
51
+ id: r['id'],
52
+ amount: r['amount'],
53
+ recipient_id: r['recipient_id'],
54
+ status: r['status'],
55
+ currency: r['currency']
56
+ ) }
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def url(path)
63
+ "#{@api_endpoint_url}/#{path}"
64
+ end
65
+
66
+ # Required parameters: method
67
+ # Optional parameters: headers, body, query (all hashes)
68
+ def call_api(path, params = {})
69
+ raise ArgumentError, 'You must include an HTTP method' unless params[:method]
70
+ raise InvalidConnection, 'You have not authenticated and have no token' unless @token
71
+ headers = {
72
+ 'Content-Type' => 'application/json',
73
+ 'Authorization' => "Bearer #{@token}"
74
+ }
75
+ headers.merge!(params[:headers]) if params[:headers]
76
+
77
+ arguments = {headers: headers}
78
+ arguments.merge!({body: params[:body].to_json}) if params[:body]
79
+ arguments.merge!({query: params[:query]}) if params[:query]
80
+
81
+ HTTParty.send params[:method], url(path), arguments
82
+ end
83
+
84
+ def authenticate!
85
+ headers = {'Content-Type' => 'application/json'}
86
+ body = {username: @username, apikey: @api_key}
87
+ res = HTTParty.post url('/login'), body: body.to_json, headers: headers
88
+ if res.code == 200
89
+ @token = JSON.parse(res.body)["token"]
90
+ else
91
+ raise InvalidConnection, 'Connection failed. Maybe your connection credentials are incorrect?'
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1 @@
1
+ class InvalidConnection < StandardError; end
@@ -0,0 +1,12 @@
1
+ module Coolpay
2
+ class Payment
3
+ attr_reader :id, :amount, :currency, :recipient_id, :status
4
+ def initialize(id:,amount:,currency:,recipient_id:,status:)
5
+ @id = id
6
+ @amount = amount
7
+ @currency = currency
8
+ @recipient_id = recipient_id
9
+ @status = status
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,9 @@
1
+ module Coolpay
2
+ class Recipient
3
+ attr_reader :name, :id
4
+ def initialize(name:, id:)
5
+ @name = name
6
+ @id = id
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Coolpay
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/lib/coolpay.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'json'
2
+ require 'httparty'
3
+
4
+ require 'coolpay/version'
5
+ require 'coolpay/exceptions'
6
+ require 'coolpay/connection'
7
+ require 'coolpay/recipient'
8
+ require 'coolpay/payment'
9
+
10
+ # Coolpay API Wrapper
11
+ module Coolpay
12
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dannysmith_coolpay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Danny Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-doc
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: httparty
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: json
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Gem to wrap the Coolpay API.
154
+ email:
155
+ - hi@danny.is
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - CODE_OF_CONDUCT.md
164
+ - Gemfile
165
+ - LICENSE.txt
166
+ - README.md
167
+ - Rakefile
168
+ - bin/console
169
+ - bin/setup
170
+ - coolpay.gemspec
171
+ - lib/coolpay.rb
172
+ - lib/coolpay/connection.rb
173
+ - lib/coolpay/exceptions.rb
174
+ - lib/coolpay/payment.rb
175
+ - lib/coolpay/recipient.rb
176
+ - lib/coolpay/version.rb
177
+ homepage: http://github.com/dannysmith/coolpay
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.6.12
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Gem to wrap the Coolpay API.
201
+ test_files: []