espago 0.0.9 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -0
- data/Gemfile.lock +14 -1
- data/Guardfile +1 -0
- data/README.md +118 -6
- data/espago.gemspec +6 -1
- data/lib/espago.rb +4 -3
- data/lib/espago/api_connection.rb +16 -7
- data/lib/espago/api_connection/{post_clients.rb → api.rb} +1 -5
- data/lib/espago/api_connection/api_delete.rb +9 -0
- data/lib/espago/api_connection/api_get.rb +13 -0
- data/lib/espago/api_connection/api_post.rb +9 -0
- data/lib/espago/api_connection/api_put.rb +9 -0
- data/lib/espago/api_connection/charges_complete_post.rb +9 -0
- data/lib/espago/api_connection/charges_delete.rb +9 -0
- data/lib/espago/api_connection/charges_get.rb +9 -0
- data/lib/espago/api_connection/charges_post.rb +9 -0
- data/lib/espago/api_connection/{post_charges_refund.rb → charges_refund_post.rb} +1 -5
- data/lib/espago/api_connection/clients_authorize_post.rb +9 -0
- data/lib/espago/api_connection/clients_delete.rb +9 -0
- data/lib/espago/api_connection/clients_get.rb +9 -0
- data/lib/espago/api_connection/clients_invoices_get.rb +9 -0
- data/lib/espago/api_connection/clients_post.rb +9 -0
- data/lib/espago/api_connection/clients_put.rb +9 -0
- data/lib/espago/api_connection/clients_subscriptions_get.rb +9 -0
- data/lib/espago/api_connection/complete_post.rb +14 -0
- data/lib/espago/api_connection/invoice_items_delete.rb +9 -0
- data/lib/espago/api_connection/invoice_items_get.rb +9 -0
- data/lib/espago/api_connection/invoice_items_post.rb +9 -0
- data/lib/espago/api_connection/invoices_get.rb +9 -0
- data/lib/espago/api_connection/line_items_get.rb +9 -0
- data/lib/espago/api_connection/plans_delete.rb +9 -0
- data/lib/espago/api_connection/plans_get.rb +9 -0
- data/lib/espago/api_connection/plans_post.rb +9 -0
- data/lib/espago/api_connection/plans_put.rb +9 -0
- data/lib/espago/api_connection/subscriptions_delete.rb +9 -0
- data/lib/espago/api_connection/subscriptions_get.rb +9 -0
- data/lib/espago/api_connection/subscriptions_post.rb +9 -0
- data/lib/espago/api_connection/tokens_get.rb +9 -0
- data/lib/espago/api_connection/{post_tokens.rb → tokens_post.rb} +2 -2
- data/lib/espago/back_request.rb +33 -0
- data/lib/espago/client.rb +12 -3
- data/lib/espago/router.rb +1 -1
- data/lib/espago/version.rb +1 -1
- data/spec/espago/api_connection_spec.rb +4 -3
- data/spec/espago/back_request_spec.rb +33 -0
- data/spec/espago/client_spec.rb +3 -2
- data/spec/espago/router_spec.rb +2 -2
- data/spec/features/apis_spec.rb +21 -0
- data/spec/features/charges_spec.rb +79 -0
- data/spec/features/clients_spec.rb +100 -0
- data/spec/features/error_spec.rb +28 -0
- data/spec/features/invoice_items_spec.rb +37 -0
- data/spec/features/invoices_spec.rb +24 -0
- data/spec/features/line_items_spec.rb +17 -0
- data/spec/features/plans_spec.rb +61 -0
- data/spec/features/subscriptions_spec.rb +43 -0
- data/spec/features/tokens_spec.rb +40 -0
- data/spec/fixtures/cassettes/api_2.yml +68 -0
- data/spec/fixtures/cassettes/api_3.yml +68 -0
- data/spec/fixtures/cassettes/charges_complete.yml +48 -0
- data/spec/fixtures/cassettes/charges_complete_deprecation.yml +48 -0
- data/spec/fixtures/cassettes/charges_destroy.yml +46 -0
- data/spec/fixtures/cassettes/charges_get.yml +67 -0
- data/spec/fixtures/cassettes/charges_get_pay_mTOngouLTJWZ0w.yml +46 -0
- data/spec/fixtures/cassettes/charges_post.yml +48 -0
- data/spec/fixtures/cassettes/charges_refund.yml +48 -0
- data/spec/fixtures/cassettes/clients_authorize.yml +48 -0
- data/spec/fixtures/cassettes/clients_delete.yml +42 -0
- data/spec/fixtures/cassettes/clients_get.yml +46 -0
- data/spec/fixtures/cassettes/clients_get_cli_w0Se2smYwyQ0Uw.yml +46 -0
- data/spec/fixtures/cassettes/clients_invoices.yml +46 -0
- data/spec/fixtures/cassettes/clients_post.yml +48 -0
- data/spec/fixtures/cassettes/clients_put.yml +48 -0
- data/spec/fixtures/cassettes/clients_subscriptions.yml +46 -0
- data/spec/fixtures/cassettes/error_400.yml +46 -0
- data/spec/fixtures/cassettes/error_401.yml +46 -0
- data/spec/fixtures/cassettes/error_500.yml +46 -0
- data/spec/fixtures/cassettes/invoice_items_delete_ii_WDzszvhTshe78Xd.yml +42 -0
- data/spec/fixtures/cassettes/invoice_items_get_ii_5LS-YR7S1QaJBl3.yml +47 -0
- data/spec/fixtures/cassettes/invoice_items_post_ii_5LS-YR7S1QaJBl3.yml +49 -0
- data/spec/fixtures/cassettes/invoices_get.yml +46 -0
- data/spec/fixtures/cassettes/invoices_get_in_tUCMhwlg2nkvAaL.yml +46 -0
- data/spec/fixtures/cassettes/line_items_get.yml +47 -0
- data/spec/fixtures/cassettes/plans_delete.yml +42 -0
- data/spec/fixtures/cassettes/plans_get.yml +46 -0
- data/spec/fixtures/cassettes/plans_get_pl_12345.yml +46 -0
- data/spec/fixtures/cassettes/plans_post.yml +48 -0
- data/spec/fixtures/cassettes/plans_put.yml +44 -0
- data/spec/fixtures/cassettes/subscriptions_delete_sub_8yYuCBKdywr7e2.yml +42 -0
- data/spec/fixtures/cassettes/subscriptions_get.yml +46 -0
- data/spec/fixtures/cassettes/subscriptions_get_sub_8yYuCBKdywr7e2.yml +46 -0
- data/spec/fixtures/cassettes/subscriptions_post.yml +48 -0
- data/spec/fixtures/cassettes/tokens_get.yml +46 -0
- data/spec/fixtures/cassettes/tokens_post.yml +54 -0
- data/spec/spec_helper.rb +30 -0
- metadata +197 -37
- data/lib/espago/api_connection/delete_charges.rb +0 -13
- data/lib/espago/api_connection/delete_clients.rb +0 -13
- data/lib/espago/api_connection/get_charges.rb +0 -17
- data/lib/espago/api_connection/get_clients.rb +0 -17
- data/lib/espago/api_connection/get_tokens.rb +0 -13
- data/lib/espago/api_connection/post_charges.rb +0 -13
- data/lib/espago/api_connection/post_clients_authorize.rb +0 -13
- data/lib/espago/api_connection/post_complete.rb +0 -13
- data/lib/espago/api_connection/put_clients.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27e99a50c2ebe74762fb3cfbb1d808dfc465fdb9
|
4
|
+
data.tar.gz: dfeead9293c23e0c4f4d3a7ccc682d21ef327cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 206a547e448d6cf77996f7d288d9ef563042f7521f6c8d6918dba776fbfdb19708a7939fb8ad51087879035bcbd6273e4f50120691c084f1193d9ed24d492592
|
7
|
+
data.tar.gz: ac022203b3f4ede07c8ea8e2e7298e70e843456f7aedd7f5c86957c362de0914d234ca9e5996628eb35bddfb2479dbcc6bc9340ad635fe1990d2552a3df93570
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
espago (0.
|
4
|
+
espago (0.1.2)
|
5
5
|
facets
|
6
6
|
faraday
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
+
addressable (2.3.6)
|
12
|
+
codeclimate-test-reporter (0.4.1)
|
13
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
11
14
|
coderay (1.0.8)
|
15
|
+
crack (0.4.2)
|
16
|
+
safe_yaml (~> 1.0.0)
|
12
17
|
diff-lcs (1.1.3)
|
13
18
|
facets (2.9.3)
|
14
19
|
faraday (0.8.7)
|
@@ -46,17 +51,23 @@ GEM
|
|
46
51
|
rspec-instafail (0.2.4)
|
47
52
|
rspec-mocks (2.12.1)
|
48
53
|
ruby-progressbar (1.0.2)
|
54
|
+
safe_yaml (1.0.4)
|
49
55
|
simplecov (0.7.1)
|
50
56
|
multi_json (~> 1.0)
|
51
57
|
simplecov-html (~> 0.7.1)
|
52
58
|
simplecov-html (0.7.1)
|
53
59
|
slop (3.3.3)
|
54
60
|
thor (0.16.0)
|
61
|
+
vcr (2.9.3)
|
62
|
+
webmock (1.20.4)
|
63
|
+
addressable (>= 2.3.6)
|
64
|
+
crack (>= 0.3.2)
|
55
65
|
|
56
66
|
PLATFORMS
|
57
67
|
ruby
|
58
68
|
|
59
69
|
DEPENDENCIES
|
70
|
+
codeclimate-test-reporter
|
60
71
|
espago!
|
61
72
|
fuubar
|
62
73
|
guard-rspec
|
@@ -65,3 +76,5 @@ DEPENDENCIES
|
|
65
76
|
rb-fsevent (~> 0.9.1)
|
66
77
|
rspec
|
67
78
|
simplecov
|
79
|
+
vcr
|
80
|
+
webmock
|
data/Guardfile
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,9 @@ Espago gem
|
|
2
2
|
======
|
3
3
|
|
4
4
|
[![Build Status](https://travis-ci.org/espago/espago.png?branch=master)](https://travis-ci.org/espago/espago)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/espago.svg)](http://badge.fury.io/rb/espago)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/espago/espago/badges/gpa.svg)](https://codeclimate.com/github/espago/espago)
|
7
|
+
[![Test Coverage](https://codeclimate.com/github/espago/espago/badges/coverage.svg)](https://codeclimate.com/github/espago/espago)
|
5
8
|
|
6
9
|
### Installing Espago gem
|
7
10
|
|
@@ -11,9 +14,7 @@ or just add it to your Gemfile if you are running a Rails project
|
|
11
14
|
|
12
15
|
## Configuration
|
13
16
|
|
14
|
-
After registering at <http://espago.com> configure your app with the security credentials.
|
15
|
-
|
16
|
-
### Global
|
17
|
+
After registering at <http://espago.com> configure your app with the security credentials. More information about configuration of merchant account you can find in our documentation <https://espago.com/doc/en>
|
17
18
|
|
18
19
|
The most standard way of configuring Espago is to do it globally on the Espago class.
|
19
20
|
|
@@ -21,8 +22,119 @@ The most standard way of configuring Espago is to do it globally on the Espago c
|
|
21
22
|
Espago.app_password = 'your-espago-secret'
|
22
23
|
Espago.public_key = 'your-espago-key'
|
23
24
|
Espago.production = false #sets Espago enviroment to sandbox
|
25
|
+
Espago.api_version = 2
|
26
|
+
|
27
|
+
## Sending request
|
28
|
+
|
29
|
+
There are two possible ways of sending requests by using Espago gem.
|
30
|
+
The first possibility is to call everytime send_request() function with proper path, HTTP method and parameters.
|
31
|
+
|
32
|
+
Espago.send_request path, request_type, [parameters]
|
33
|
+
|
34
|
+
Here it is an example of using this way to create new client:
|
35
|
+
|
36
|
+
Espago.send_request :clients, :post, {description: "Jan Kowalski", email: "kowalski@example.com", card: {first_name: "Jan", last_name: "Kowalski", number: "4242424242424242", year: "2019", month: "03"}}
|
37
|
+
|
38
|
+
The second possible way to sending requests by Espago gem is to call the proper path on Espago object, using specific HTTP method and setting chosen parameteres.
|
39
|
+
|
40
|
+
Espago.path request_type, [parameters]
|
41
|
+
|
42
|
+
Below, it is an example of using this possibility to create new client:
|
43
|
+
|
44
|
+
Espago.clients :post, {description: "Jan Kowalski", email: "kowalski@example.com", card: {first_name: "Jan", last_name: "Kowalski", number: "4242424242424242", year: "2019", month: "03"}}
|
45
|
+
|
46
|
+
## Getting response
|
47
|
+
|
48
|
+
Every returned object includes informations about header and body of response.
|
49
|
+
|
50
|
+
For example for request:
|
51
|
+
|
52
|
+
client = Espago.clients :post, {description: "Jan Kowalski", email: "kowalski@example.com", card: {first_name: "Jan", last_name: "Kowalski", number: "4242424242424242", year: "2019", month: "03"}}
|
53
|
+
|
54
|
+
Espago returns an special response object:
|
55
|
+
|
56
|
+
#<Espago::Response:0x000001038dba40
|
57
|
+
@body=
|
58
|
+
{"email"=>"kowalski@example.com",
|
59
|
+
"id"=>"cli_N2NNf85cFB1xWs",
|
60
|
+
"created_at"=>1381834598,
|
61
|
+
"description"=>"Jan Kowalski",
|
62
|
+
"card"=>
|
63
|
+
{"company"=>"VI",
|
64
|
+
"last4"=>"4242",
|
65
|
+
"year"=>2019,
|
66
|
+
"month"=>3,
|
67
|
+
"first_name"=>"Jan",
|
68
|
+
"last_name"=>"Kowalski",
|
69
|
+
"authorized"=>nil,
|
70
|
+
"created_at"=>1381834598},
|
71
|
+
"deleted"=>false},
|
72
|
+
@status=201>
|
73
|
+
|
74
|
+
To get response status code you should use "status" method.
|
75
|
+
For example
|
76
|
+
|
77
|
+
client.status
|
78
|
+
|
79
|
+
returns "201" code.
|
80
|
+
|
81
|
+
To get body of response you should use "body" method.
|
82
|
+
For example
|
83
|
+
|
84
|
+
client.body
|
85
|
+
|
86
|
+
can return hash with client details:
|
87
|
+
|
88
|
+
{
|
89
|
+
"email"=>"kowalski@example.com",
|
90
|
+
"id"=>"cli_N2NNf85cFB1xWs",
|
91
|
+
"created_at"=>1381834598,
|
92
|
+
"description"=>"Jan Kowalski",
|
93
|
+
"card"=>
|
94
|
+
{"company"=>"VI",
|
95
|
+
"last4"=>"4242",
|
96
|
+
"year"=>2019,
|
97
|
+
"month"=>3,
|
98
|
+
"first_name"=>"Jan",
|
99
|
+
"last_name"=>"Kowalski",
|
100
|
+
"authorized"=>nil,
|
101
|
+
"created_at"=>1381834598},
|
102
|
+
"deleted"=>false
|
103
|
+
}
|
104
|
+
|
105
|
+
Now if you want get customer's e-mail(or anoher field in 1st level of response) this short code should execute operation:
|
106
|
+
|
107
|
+
client.email
|
108
|
+
=> "kowalski@example.com"
|
109
|
+
|
110
|
+
client.card
|
111
|
+
=> {"company"=>"VI", "last4"=>"4242", "year"=>2019, "month"=>3, "first_name"=>"Jan", "last_name"=>"Kowalski", "authorized"=>nil, "created_at"=>1381834598}
|
24
112
|
|
25
|
-
|
113
|
+
## All possible paths (resources)
|
26
114
|
|
27
|
-
|
28
|
-
|
115
|
+
<table align="center">
|
116
|
+
<tr>
|
117
|
+
<th>Parameter</th><th>Description</th><th>Documentation link</th>
|
118
|
+
</tr>
|
119
|
+
<tr>
|
120
|
+
<th>tokens</th><td>special id for credit card</td><td>https://developers.espago.com/en/v2#44-card-tokens</td>
|
121
|
+
</tr>
|
122
|
+
<tr>
|
123
|
+
<th>clients</th><td>clients data</td><td>https://developers.espago.com/en/v2#55-customers</td>
|
124
|
+
</tr>
|
125
|
+
<tr>
|
126
|
+
<th>charges</th><td>credit payments</td><td>https://developers.espago.com/en/v2#9-card-payments</td>
|
127
|
+
</tr>
|
128
|
+
<tr>
|
129
|
+
<th>plans</th><td>plans for recurring payments</td><td>https://developers.espago.com/en/v2#22-plans</td>
|
130
|
+
</tr>
|
131
|
+
<tr>
|
132
|
+
<th>subscriptions</th><td>recurring payments for client according to the created plan</td><td>https://developers.espago.com/en/v2#28-subscriptions</td>
|
133
|
+
</tr>
|
134
|
+
<tr>
|
135
|
+
<th>invoices</th><td>single recurring payment</td><td>https://developers.espago.com/en/v2#34-invoices</td>
|
136
|
+
</tr>
|
137
|
+
<tr>
|
138
|
+
<th>line_items</th><td>element of every invoice</td><td>https://developers.espago.com/en/v2#41-getting-informations-about-line-items-of-invoice</td>
|
139
|
+
</tr>
|
140
|
+
</table>
|
data/espago.gemspec
CHANGED
@@ -6,7 +6,7 @@ require 'espago/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "espago"
|
8
8
|
gem.version = Espago::VERSION
|
9
|
-
gem.authors = ["Piotrek", "Szymon Fiedler"]
|
9
|
+
gem.authors = ["Piotrek", "Szymon Fiedler","Waclaw Luczak"]
|
10
10
|
gem.email = ["developers@espago.com"]
|
11
11
|
gem.description = %q{Espago api wrapper}
|
12
12
|
gem.summary = %q{Espago api wrapper}
|
@@ -27,4 +27,9 @@ Gem::Specification.new do |gem|
|
|
27
27
|
gem.add_development_dependency "fuubar"
|
28
28
|
gem.add_development_dependency 'rake'
|
29
29
|
gem.add_development_dependency 'rb-fsevent', '~> 0.9.1'
|
30
|
+
gem.add_development_dependency 'webmock'
|
31
|
+
gem.add_development_dependency 'vcr'
|
32
|
+
gem.add_development_dependency 'codeclimate-test-reporter'
|
33
|
+
|
34
|
+
|
30
35
|
end
|
data/lib/espago.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "espago/version"
|
2
2
|
require "espago/client"
|
3
3
|
require "espago/router"
|
4
|
+
require "espago/back_request"
|
4
5
|
require 'forwardable'
|
5
6
|
|
6
7
|
module Espago
|
@@ -8,8 +9,8 @@ module Espago
|
|
8
9
|
class << self
|
9
10
|
extend Forwardable
|
10
11
|
|
11
|
-
def_delegators :default_client, :public_key, :app_id, :app_password, :send_request, :production
|
12
|
-
def_delegators :default_client, :public_key= , :app_id= , :app_password=, :production=
|
12
|
+
def_delegators :default_client, :public_key, :app_id, :app_password, :api_version, :send_request, :production
|
13
|
+
def_delegators :default_client, :public_key= , :app_id= , :app_password=, :api_version=, :production=
|
13
14
|
|
14
15
|
def method_missing(method, *args, &block)
|
15
16
|
if Router.new(method, args[0]).path_exists?
|
@@ -24,4 +25,4 @@ module Espago
|
|
24
25
|
@default_client ||= Espago::Client.new
|
25
26
|
end
|
26
27
|
end
|
27
|
-
end
|
28
|
+
end
|
@@ -6,16 +6,28 @@ require "espago/error"
|
|
6
6
|
require "espago/response"
|
7
7
|
require "facets/kernel/require_all"
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
require "espago/api_connection/api"
|
10
|
+
require "espago/api_connection/api_delete"
|
11
|
+
require "espago/api_connection/api_get"
|
12
|
+
require "espago/api_connection/api_post"
|
13
|
+
require "espago/api_connection/api_put"
|
14
|
+
|
15
|
+
begin
|
16
|
+
require_all "error/*"
|
17
|
+
require_all "api_connection/*"
|
18
|
+
rescue LoadError #if "require_all" method isn't from kernel gem
|
19
|
+
require_rel "error/*"
|
20
|
+
require_rel "api_connection/*"
|
21
|
+
end
|
11
22
|
|
12
23
|
module Espago
|
13
24
|
class ApiConnection
|
14
25
|
extend Forwardable
|
15
26
|
def_delegator :@connection, :basic_auth, :authenticate
|
16
27
|
|
17
|
-
def initialize(enviroment)
|
28
|
+
def initialize(enviroment,headers)
|
18
29
|
@connection = Faraday.new(enviroment)
|
30
|
+
@connection.headers = headers
|
19
31
|
@router = Router
|
20
32
|
end
|
21
33
|
|
@@ -37,7 +49,7 @@ module Espago
|
|
37
49
|
when 401
|
38
50
|
raise authentication_error(response)
|
39
51
|
else
|
40
|
-
raise api_error(response
|
52
|
+
raise api_error(response)
|
41
53
|
end
|
42
54
|
end
|
43
55
|
|
@@ -53,8 +65,5 @@ module Espago
|
|
53
65
|
ApiError.new(response)
|
54
66
|
end
|
55
67
|
|
56
|
-
def parse(body)
|
57
|
-
JSON.parse body
|
58
|
-
end
|
59
68
|
end
|
60
69
|
end
|