telleroo 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: e58a73456b50f8d6c1baa85d5d3908491edb20ef
4
+ data.tar.gz: 3c67b94c2c312a133e542c032f63af145264187a
5
+ SHA512:
6
+ metadata.gz: e36502edacc356742e3bdd7dec3bf479e070bb863c834a2a7a5441a9979962c5c38259617e6afb381de112959c0fd1f4099bff1843b3e2b429e885427b918789
7
+ data.tar.gz: eadbe341d18c934bee16e03385055a9a93e0b4683c94a7b6fd137995dd9e16e64cb5f67a8c9291b1f8143f0a7e60478793d4030c4fbb7d5ac7816192937ec4bc
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in telleroo.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec, cmd: 'bundle exec rspec' do
5
+ watch('spec/spec_helper.rb') { 'spec' }
6
+ watch('spec/rails_helper.rb') { 'spec' }
7
+ watch(%r{^spec/.+_spec\.rb$})
8
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 nick
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,172 @@
1
+ # Telleroo
2
+
3
+ This is a simple wrapper for the Telleroo API. API Documentation is [available here](http://docs.telleroo.com). This gem uses `MultiJson` to parse responses which are otherwise returned unadulterated.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'telleroo'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install telleroo
20
+
21
+ ## Configuration
22
+
23
+ `Telleroo::Client` can be configured from an initializer:
24
+
25
+ ```
26
+
27
+ Telleroo.configure do |config|
28
+ config.authorization_token = "YOUR_AUTH_TOKEN"
29
+ config.endpoint = 'https://sandbox.telleroo.com'
30
+ end
31
+
32
+ ```
33
+
34
+ or by passing an options block to `Telleroo::Client.new`
35
+
36
+ ```
37
+
38
+ client = Telleroo::Client.new do |config|
39
+ config.authorization_token = "YOUR_AUTH_TOKEN"
40
+ config.endpoint = 'https://sandbox.telleroo.com'
41
+ end
42
+
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ After configuring a `client`, the following calls are available to you:
48
+
49
+ **List Accounts**
50
+
51
+ Retrieves all bank accounts assigned to your company
52
+ ```
53
+ client.accounts()
54
+
55
+ ```
56
+
57
+ **List Recipients**
58
+
59
+ Retrieves all recipients under your company.
60
+ ```
61
+ client.recipients()
62
+
63
+ ```
64
+
65
+ **Get Recipient**
66
+
67
+ Retrieves a single recipient given a recipient_id.
68
+
69
+ ```
70
+ client.get_recipient("ff17b231-2bc4-485e-967e-231867e15fd6")
71
+
72
+ ```
73
+
74
+ **Create Recipient**
75
+
76
+ Creates a single recipient.
77
+
78
+ Note: `GBP` Recipients require `account_no` and `sort_code` passed in `options` while `EUR` require `iban` and `bic`.
79
+
80
+ ```
81
+ client.create_recipient(name: 'Nick Lloyd',
82
+ currency_code: 'GBP',
83
+ options: {
84
+ account_no: '72345678',
85
+ sort_code: '623456'
86
+ }
87
+ )
88
+ ```
89
+
90
+ **Delete Recipient**
91
+
92
+ Retrieves a single recipient given a recipient_id.
93
+
94
+ ```
95
+ client.delete_recipient("ff17b231-2bc4-485e-967e-231867e15fd6")
96
+
97
+ ```
98
+
99
+ **Create Bank Transfer to Recipient**
100
+
101
+ Triggers an instantaneous bank transfer to a existing recipient from your account. [See docs](http://docs.telleroo.com/#bank-transfers-to-recipient-id) for additional available params to pass into options.
102
+
103
+ ```
104
+ client.create_transfer(
105
+ account_id: 'a6a2b79c-33b5-4ed5-90fd-bfb8f1d4085a',
106
+ currency_code: 'GBP',
107
+ amount: 10000,
108
+ recipient_id: 'ff17b231-2bc4-485e-967e-231867e15fd6',
109
+ idempotent_key: 'abcd-123456789-efgh',
110
+ options: {
111
+ reference: 'foobar'
112
+ }
113
+ )
114
+ ```
115
+
116
+ **Create an Adhoc Bank Transfer**
117
+
118
+ Send all params required to both create a Recipient and transfer funds in a single call.
119
+
120
+ ```
121
+ client.create_adhoc_transfer({
122
+ account_id: 'a6a2b77c-33b5-4ed5-90fd-bfb8f1d4085a',
123
+ currency_code: 'GBP',
124
+ amount: 10000,
125
+ recipient_name: 'Rick Floyd',
126
+ account_no: 12345678,
127
+ sort_code: 665544,
128
+ idempotent_key: 'abcd-123456789-efgh',
129
+ reference: 'foo',
130
+ tag: 'bar',
131
+ reconciliation: 'baz'
132
+ })
133
+
134
+ ```
135
+
136
+ **List Transactions**
137
+
138
+ Returns all activity on a specified bank account. [See docs](http://docs.telleroo.com/#transactions-list) for additional available params to pass into options.
139
+
140
+ ```
141
+ client.transactions(
142
+ account_id: 'a6a2b77c-33b5-4ed5-90fd-bfb8f1d4085a',
143
+ start_date: '09-06-2017',
144
+ end_date: '09-07-2017'
145
+ )
146
+
147
+ ```
148
+
149
+ **Get Transaction**
150
+
151
+ Retrieves all relevant data of a single transaction including the transfer status.
152
+
153
+ ```
154
+ get_transaction(id)
155
+
156
+ ```
157
+
158
+ ## Development
159
+
160
+ 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.
161
+
162
+ 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).
163
+
164
+ ## Contributing
165
+
166
+ Bug reports and pull requests are welcome on GitHub at https://github.com/playpasshq/telleroo.
167
+
168
+
169
+ ## License
170
+
171
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
172
+
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/lib/telleroo.rb ADDED
@@ -0,0 +1,25 @@
1
+ require 'active_support/inflector'
2
+ require 'telleroo/version'
3
+ require 'telleroo/configuration'
4
+ require 'telleroo/client'
5
+
6
+ ActiveSupport::Inflector.inflections(:en) do |inflect|
7
+ inflect.acronym 'API'
8
+ end
9
+
10
+ module Telleroo
11
+ def self.config
12
+ @config ||= Configuration.new
13
+ end
14
+
15
+ def self.configure
16
+ yield config
17
+ end
18
+
19
+ # Return the config values set in this module
20
+ def self.options
21
+ Hash[
22
+ * Configuration::VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten
23
+ ]
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'telleroo/api/accounts'
2
+ require 'telleroo/api/recipients'
3
+ require 'telleroo/api/bank_transfers'
4
+ require 'telleroo/api/transactions'
5
+
6
+ module Telleroo
7
+ # Includes all API Modules
8
+ module API
9
+ include Telleroo::API::Accounts
10
+ include Telleroo::API::Recipients
11
+ include Telleroo::API::BankTransfers
12
+ include Telleroo::API::Transactions
13
+ end
14
+ end
@@ -0,0 +1,17 @@
1
+ module Telleroo
2
+ module API
3
+ # Telleroo Accounts. These are Bank Accounts
4
+ module Accounts
5
+ # The default name of the bank account is primary account, which is
6
+ # accessible through a unique id. Your account number and sort code
7
+ # are returned here as well. All bank accounts linked to your
8
+ # company are returned with this request.
9
+
10
+ # Returns bank accounts list
11
+ # @return [Array]
12
+ def accounts
13
+ get('accounts')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,87 @@
1
+ module Telleroo
2
+ module API
3
+ # Telleroo Transfers. These are bank transfers from your
4
+ # Source Account to Recipient
5
+ module BankTransfers
6
+ # This triggers an instantaneous bank transfer to a existing recipient -
7
+ # Faster Payments per default - out of your primary account.
8
+ # Telleroo gives you back a unique transfer_id that can be referenced on
9
+ # the statement.
10
+ # The default currency is GBP and the format is pence (100 equals 1 GBP).
11
+ # All transfers are approved per default and are directly placed into
12
+ # the payments scheme after passing through validation
13
+ # (e.g. sufficient account balance).
14
+
15
+ # Instructs bank transfer to a saved recipient
16
+
17
+ # @param [String] account_id Telleroo ID of the Source Account
18
+ # @param [String] currency_code Currency of Account
19
+ # @param [Integer] amount The Amount in cents of the transfer
20
+ # @param [String] idempotent_key Unique key for each transaction
21
+ # @param [Hash] options Optional Detail
22
+
23
+ # {
24
+ # "bank_transfer": {
25
+ # "id": "842963c5-e230-42ef-8de8-2b7a459026",
26
+ # "processed_at": "2016-12-02T12:15:22.486Z",
27
+ # "transaction_type": "Debit",
28
+ # "currency_code": "GBP",
29
+ # "amount": 100,
30
+ # "recipient_id": "ff17b231-2bc4-485e-967e-231867e15fd6",
31
+ # "status": "Preparing Payment",
32
+ # "status_info": "Creating payment request",
33
+ # "reconciliation": "f9q3408rh3",
34
+ # "reference": "PayslipDec16",
35
+ # "account_id": "ed5af7d2-741c-4905-a3ba-66d332d604",
36
+ # "tag": "Payroll",
37
+ # "end_balance": 2100,
38
+ # "idempotent_key": "2130948",
39
+ # "created_at": "2017-3-08T13:15:32.237Z",
40
+ # "updated_at": "2017-3-08T13:15:32.237Z"
41
+ # }
42
+ # }
43
+
44
+ # @return [Hash]
45
+ def create_transfer(account_id: nil, currency_code: nil, amount: nil, recipient_id: nil, idempotent_key: nil, options: {})
46
+ params = {
47
+ account_id: account_id,
48
+ currency_code: currency_code,
49
+ amount: amount,
50
+ recipient_id: recipient_id,
51
+ idempotent_key: idempotent_key
52
+ }.merge(options)
53
+
54
+ post('bank_transfers', params)
55
+ end
56
+
57
+ # Send all params to both create a Recipient and transfer funds in
58
+ # a single call.
59
+
60
+ # {
61
+ # "bank_transfer": {
62
+ # "id": "842963c5-e230-42ef-8de8-2b7a459026",
63
+ # "processed_at": "2016-12-02T12:15:22.486Z",
64
+ # "transaction_type": "Debit",
65
+ # "currency_code": "GBP",
66
+ # "amount": 100,
67
+ # "recipient_id": "ff17b231-2bc4-485e-967e-231867e15fd6",
68
+ # "status": "Preparing Payment",
69
+ # "status_info": "Creating payment request",
70
+ # "reconciliation": "f9q3408rh3",
71
+ # "reference": "PayslipDec16",
72
+ # "account_id": "ed5af7d2-741c-4905-a3ba-66d332d604",
73
+ # "tag": "Payroll",
74
+ # "end_balance": 2100,
75
+ # "idempotent_key": "2130948",
76
+ # "created_at": "2017-3-08T13:15:32.237Z",
77
+ # "updated_at": "2017-3-08T13:15:32.237Z"
78
+ # }
79
+ # }
80
+
81
+ # @return [Hash]
82
+ def create_adhoc_transfer(params)
83
+ post('adhoc_bank_transfers', params)
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,79 @@
1
+ module Telleroo
2
+ module API
3
+ # Telleroo Recipients. These are Bank Accounts that receive funds
4
+ module Recipients
5
+ # Return all Recipients associated to your account
6
+
7
+ # {
8
+ # "recipients": [
9
+ # {
10
+ # "id": "ff17b231-2bc4-485e-967e-231867e15fd6",
11
+ # "name": "John Archer",
12
+ # "currency_code": "GBP",
13
+ # "account_no": "12345678",
14
+ # "sort_code": "123456",
15
+ # "legal_type": "PRIVATE"
16
+ # },
17
+ # {
18
+ # "id": "1fdfef97-95b8-4985-917a-5d9ac9d52d35",
19
+ # "name": "Antonio Silva",
20
+ # "currency_code": "EUR",
21
+ # "iban": "12345678901234567",
22
+ # "bic": "12345678901",
23
+ # "legal_type": "PRIVATE"
24
+ # }
25
+ # ]
26
+ # }
27
+
28
+ # @return [Array]
29
+ def recipients
30
+ get('recipients')
31
+ end
32
+
33
+ # This endpoint retrieves a single recipient by entering the recipient_id
34
+
35
+ # @param [String] id The Telleroo ID of the Recipient
36
+ # @return [Hash]
37
+ def get_recipient(id)
38
+ get("recipients/#{id}")
39
+ end
40
+
41
+ # This creates a new recipient. Telleroo gives you back a unique
42
+ # recipient_id that can be referenced when creating a bank transfer.
43
+
44
+ # @param [String] name The name of the Account Holder
45
+ # @param [String] currency_code Currency of Account
46
+ # @param [Hash] options Optional Account Detail
47
+
48
+ # {
49
+ # "recipient": {
50
+ # "id": "ff17b231-2bc4-485e-967e-231867e15fd6",
51
+ # "name": "Jefke Vermeulen",
52
+ # "currency_code": "GBP",
53
+ # "account_no": "12345678",
54
+ # "sort_code": "224657",
55
+ # "legal_type": "PRIVATE"
56
+ # }
57
+ # }
58
+
59
+ # @return [Hash]
60
+
61
+ def create_recipient(name: nil, currency_code: nil, options: {})
62
+ params = {
63
+ name: name,
64
+ currency_code: currency_code
65
+ }.merge(options)
66
+
67
+ post('recipients', params)
68
+ end
69
+
70
+ # This removes a recipient. Removing a recipient means you
71
+ # can no longer use their recipient ID.
72
+
73
+ # @param [String] id The Telleroo ID of the Recipient
74
+ def delete_recipient(id)
75
+ delete("recipients/#{id}")
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,98 @@
1
+ module Telleroo
2
+ module API
3
+ # Telleroo Accounts. These are Bank Accounts
4
+ module Transactions
5
+ # This returns all activity on a specified bank account.
6
+
7
+ # Returns transaction overview
8
+
9
+ # @param [String] account_id Telleroo ID of the Source Account
10
+ # @param [Date] start_date Filetr results by start date (DD-MM-YYYY)
11
+ # @param [Date] end_date Filter results by end date (DD-MM-YYYY)
12
+ # @param [Integer] page pagination
13
+
14
+ # {
15
+ # "transactions": [
16
+ # {
17
+ # "id": "842963c5-e230-42ef-8de8-2b7a459026",
18
+ # "processed_at": "2016-12-01T12:15:23.486Z",
19
+ # "transaction_type": "Credit",
20
+ # "currency_code": "GBP",
21
+ # "amount": "1000",
22
+ # "recipient_id": null,
23
+ # "status": "Credited",
24
+ # "status_info": "Funds successfully credited",
25
+ # "reconciliation": "3456yujk",
26
+ # "reference": "Funding Telleroo",
27
+ # "account_id": "ed5af7d2-741c-4905-a3ba-66d332d604",
28
+ # "tag": "Sponsoring",
29
+ # "end_balance": 1560,
30
+ # "created_at": "2016-12-01T12:15:22.486Z",
31
+ # "updated_at": "2016-12-01T12:15:22.486Z"
32
+ # },
33
+ # {
34
+ # "id": "842963c5-e230-42ef-8de8-2b7a459026",
35
+ # "processed_at": "2016-12-01T12:15:23.486Z",
36
+ # "transaction_type": "Debit",
37
+ # "currency_code": "GBP",
38
+ # "amount": "100",
39
+ # "recipient_id": "122963c5-e230-42ef-8de8-327459026",
40
+ # "status": "Preparing Payment",
41
+ # "status_info": "Creating payment request",
42
+ # "reconciliation": "f9q3408rh3",
43
+ # "reference": "Withdrawal Telleroo",
44
+ # "account_id": "ed5af7d2-741c-4905-a3ba-66d332d604",
45
+ # "tag": "Manutd",
46
+ # "end_balance": 1460,
47
+ # "idempotent_key": "6130348",
48
+ # "created_at": "2016-12-01T12:15:22.486Z",
49
+ # "updated_at": "2016-12-01T12:15:22.486Z"
50
+ # }
51
+ # ]
52
+ # }
53
+
54
+ # @return [Array]
55
+ def transactions(account_id: nil, start_date: nil, end_date: nil, page: 1)
56
+ params = {
57
+ account_id: account_id,
58
+ start_date: start_date,
59
+ end_date: end_date,
60
+ page: page
61
+ }
62
+ get('transactions', params)
63
+ end
64
+
65
+ # This endpoint retrieves a single transaction by entering
66
+ # the transaction_id
67
+
68
+ # Show single transaction
69
+ # @param [String] id The Telleroo ID of the Transaction
70
+
71
+ # {
72
+ # "transaction": {
73
+ # "id": "842963c5-e230-42ef-8de8-2b7a459026",
74
+ # "processed_at": "2016-12-01T12:15:23.486Z",
75
+ # "transaction_type": "Debit",
76
+ # "currency_code": "GBP",
77
+ # "amount": 100,
78
+ # "recipient_id": "442663c5-e230-32ef-8de8-1b7a459026",
79
+ # "status": "Preparing Payment",
80
+ # "status_info": "Creating payment request",
81
+ # "reconciliation": "f9q3408rh3",
82
+ # "reference": "Withdrawal Telleroo",
83
+ # "account_id": "ed5af7d2-741c-4905-a3ba-66d332d604",
84
+ # "tag": "Manutd",
85
+ # "end_balance": 2200,
86
+ # "idempotent_key": "6130348",
87
+ # "created_at": "2016-12-02T12:15:22.486Z",
88
+ # "updated_at": "2016-12-02T12:15:22.486Z"
89
+ # }
90
+ # }
91
+
92
+ # @return [Hash]
93
+ def get_transaction(id)
94
+ get("transactions/#{id}")
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,37 @@
1
+ require 'telleroo/connection'
2
+ require 'telleroo/request'
3
+ require 'telleroo/api'
4
+
5
+ module Telleroo
6
+ # Client for the Telleroo API
7
+ class Client
8
+ include Telleroo::Connection
9
+ include Telleroo::Request
10
+ include Telleroo::API
11
+
12
+ # Define the same set of accessors as the Telleroo module
13
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
14
+ attr_accessor :last_response
15
+
16
+ # Initializes a new Client object
17
+ #
18
+ # @param options [Hash]
19
+ # @return [Telleroo::Client]
20
+ def initialize(options = {})
21
+ # Merge the config values from the module and those passed
22
+ # to the client.
23
+ merged_options = Telleroo.config.options.merge(options)
24
+
25
+ # Copy the merged values to this client and ignore those
26
+ # not part of our configuration
27
+ Configuration::VALID_CONFIG_KEYS.each do |key|
28
+ send("#{key}=", merged_options[key])
29
+ end
30
+ yield(self) if block_given?
31
+ end
32
+
33
+ def last_response
34
+ @last_response if defined? @last_response
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'active_support/configurable'
2
+
3
+ module Telleroo
4
+ # Configuration.
5
+ #
6
+ # Allows this:
7
+ # Telleroo.configure do |config|
8
+ # config.authorization_token = 'deadbeef'
9
+ # config.endpoint = 'https://sandbox.telleroo.com'
10
+ # end
11
+
12
+ class Configuration
13
+ include ActiveSupport::Configurable
14
+ VALID_CONFIG_KEYS = [:authorization_token, :endpoint].freeze
15
+
16
+ config_accessor :authorization_token
17
+
18
+ config_accessor :endpoint do
19
+ 'https://sandbox.telleroo.com'
20
+ end
21
+
22
+ # Return the configuration values set in this module
23
+ def options
24
+ Hash[
25
+ *Configuration::VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten
26
+ ]
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,20 @@
1
+ require 'faraday'
2
+ require 'telleroo/response/raise_client_error'
3
+ require 'telleroo/response/raise_server_error'
4
+
5
+ module Telleroo
6
+ # Setup Faraday Connection to use for requests
7
+ module Connection
8
+ private
9
+
10
+ def connection
11
+ @connection ||= Faraday.new(url: @endpoint) do |faraday|
12
+ faraday.use Telleroo::Response::RaiseClientError
13
+ faraday.use Telleroo::Response::RaiseServerError
14
+ faraday.headers['Authorization'] = @authorization_token
15
+ faraday.headers['Content-Type'] = 'application/json'
16
+ faraday.adapter Faraday.default_adapter
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ module Telleroo
2
+ # Handle Errors returned from API
3
+ class Error < StandardError
4
+ attr_reader :http_headers
5
+
6
+ def initialize(message, http_headers)
7
+ @http_headers = http_headers
8
+ super(message)
9
+ end
10
+
11
+ class ServerError < Telleroo::Error; end
12
+ class ServiceUnavailable < Error::ServerError; end
13
+ class ApplicationError < Error::ServerError; end
14
+
15
+ class ClientError < Telleroo::Error; end
16
+ class Unauthorized < Error::ClientError; end
17
+ class NotAcceptable < Error::ClientError; end
18
+ class Unprocessable < Error::ClientError; end
19
+ class RateLimit < Error::ClientError; end
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'multi_json'
2
+
3
+ module Telleroo
4
+ # Handles HTTP requests
5
+ module Request
6
+ def get(path, params = {}, options = {})
7
+ request(:get, path, params, options)
8
+ end
9
+
10
+ def post(path, params = {}, options = {})
11
+ request(:post, path, params, options)
12
+ end
13
+
14
+ def delete(path, params = {}, options = {})
15
+ request(:delete, path, params, options)
16
+ end
17
+
18
+ private
19
+
20
+ # @return [Hash]
21
+ def request(method, path, params, _options)
22
+ response = connection.run_request(method, nil, nil, nil) do |request|
23
+ case method.to_sym
24
+ when :get, :delete
25
+ request.url(path, params)
26
+ when :post
27
+ request.path = path
28
+ request.body = JSON.dump(params) unless params.empty?
29
+ end
30
+ end
31
+
32
+ @last_response = response
33
+ load_json(response.body) unless response.body.empty?
34
+ end
35
+
36
+ def load_json(response)
37
+ MultiJson.load(response, symbolize_keys: true)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ require 'faraday'
2
+ require 'telleroo/error'
3
+
4
+ module Telleroo
5
+ module Response
6
+ # Handles API Response Errors
7
+ class RaiseClientError < Faraday::Response::Middleware
8
+ def on_complete(env)
9
+ status = env[:status].to_i
10
+ body = env[:body]
11
+ headers = env[:response_headers]
12
+
13
+ case status
14
+ when 401
15
+ raise Telleroo::Error::Unauthorized.new body, headers
16
+ when 406
17
+ raise Telleroo::Error::NotAcceptable.new body, headers
18
+ when 422
19
+ raise Telleroo::Error::Unprocessable.new body, headers
20
+ when 429
21
+ raise Telleroo::Error::RateLimit.new body, headers
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ require 'faraday'
2
+ require 'telleroo/error'
3
+
4
+ module Telleroo
5
+ module Response
6
+ # Handle Server Errors
7
+ class RaiseServerError < Faraday::Response::Middleware
8
+ def on_complete(env)
9
+ status = env[:status].to_i
10
+ headers = env[:response_headers]
11
+
12
+ case status
13
+ when 500
14
+ raise Telleroo::Error::ApplicationError.new "500 Something went wrong on our end. Please try again later.", headers
15
+ when 503
16
+ raise Telleroo::Error::ServiceUnavailable.new "503 No server is available to handle this request.", headers
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Telleroo
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/telleroo.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'telleroo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'telleroo'
8
+ spec.version = Telleroo::VERSION
9
+ spec.authors = ['Nick Lloyd']
10
+ spec.email = ['nick@playpass.be']
11
+
12
+ spec.description = 'A Ruby interface to the Telleroo API.'
13
+ spec.summary = spec.description
14
+ spec.homepage = 'https://github.com/playpasshq/telleroo'
15
+ spec.license = 'MIT'
16
+
17
+ # # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
18
+ # # 'allowed_push_host' to allow pushing to a single host or delete this
19
+ # section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = 'TODO:'
22
+ # else
23
+ # raise 'RubyGems 2.0 or newer is required to protect against ' \
24
+ # 'public gem pushes.'
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+ spec.add_dependency 'activesupport', '> 4'
35
+ spec.add_dependency 'faraday'
36
+ spec.add_dependency 'multi_json'
37
+
38
+ spec.add_development_dependency 'bundler', '~> 1.14'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec', '~> 3.0'
41
+ spec.add_development_dependency 'vcr', '~> 3.0'
42
+ spec.add_development_dependency 'webmock', '~> 3.0'
43
+ spec.add_development_dependency 'guard'
44
+ spec.add_development_dependency 'guard-rspec'
45
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: telleroo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nick Lloyd
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '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'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
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: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: A Ruby interface to the Telleroo API.
154
+ email:
155
+ - nick@playpass.be
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".travis.yml"
162
+ - Gemfile
163
+ - Guardfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - lib/telleroo.rb
168
+ - lib/telleroo/api.rb
169
+ - lib/telleroo/api/accounts.rb
170
+ - lib/telleroo/api/bank_transfers.rb
171
+ - lib/telleroo/api/recipients.rb
172
+ - lib/telleroo/api/transactions.rb
173
+ - lib/telleroo/client.rb
174
+ - lib/telleroo/configuration.rb
175
+ - lib/telleroo/connection.rb
176
+ - lib/telleroo/error.rb
177
+ - lib/telleroo/request.rb
178
+ - lib/telleroo/response/raise_client_error.rb
179
+ - lib/telleroo/response/raise_server_error.rb
180
+ - lib/telleroo/version.rb
181
+ - telleroo.gemspec
182
+ homepage: https://github.com/playpasshq/telleroo
183
+ licenses:
184
+ - MIT
185
+ metadata: {}
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 2.6.12
203
+ signing_key:
204
+ specification_version: 4
205
+ summary: A Ruby interface to the Telleroo API.
206
+ test_files: []