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
@@ -0,0 +1,14 @@
|
|
1
|
+
module Espago
|
2
|
+
class ApiConnection
|
3
|
+
class CompletePost < ApiPost
|
4
|
+
def initialize(connection)
|
5
|
+
warn "[DEPRECATION] `complete` is deprecated. Please use `charges_complete` instead."
|
6
|
+
super(connection)
|
7
|
+
end
|
8
|
+
|
9
|
+
def request(params = {})
|
10
|
+
super("charges/#{params[:charge_id]}/complete")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
module Espago
|
2
2
|
class ApiConnection
|
3
|
-
class
|
3
|
+
class TokensPost < ApiPost
|
4
4
|
def initialize(connection)
|
5
5
|
@connection = connection
|
6
6
|
@connection.basic_auth(Espago.public_key, '')
|
7
7
|
end
|
8
8
|
|
9
9
|
def request(params = {})
|
10
|
-
|
10
|
+
super("tokens", params)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "json"
|
2
|
+
require "time"
|
3
|
+
|
4
|
+
module Espago
|
5
|
+
class BackRequest
|
6
|
+
attr_reader :params
|
7
|
+
|
8
|
+
def initialize(params)
|
9
|
+
@params = parse(params)
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(attribute_name)
|
13
|
+
params[attribute_name.to_s]
|
14
|
+
end
|
15
|
+
|
16
|
+
def card
|
17
|
+
params["card"] || {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def created_at
|
21
|
+
Time.at(params["created_at"].to_i) rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def parse(params)
|
27
|
+
JSON.parse params
|
28
|
+
rescue
|
29
|
+
params
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
data/lib/espago/client.rb
CHANGED
@@ -3,17 +3,17 @@ require "espago/response"
|
|
3
3
|
|
4
4
|
module Espago
|
5
5
|
class Client
|
6
|
-
attr_accessor :public_key, :app_id, :app_password, :production
|
6
|
+
attr_accessor :public_key, :app_id, :app_password, :api_version, :production
|
7
7
|
NotAuthenticated = Class.new(StandardError)
|
8
8
|
|
9
9
|
def initialize(options = {})
|
10
|
-
@public_key, @app_id, @app_password = options.values_at( :public_key, :app_id, :app_password)
|
10
|
+
@public_key, @app_id, @app_password, @api_version = options.values_at( :public_key, :app_id, :app_password, :api_version)
|
11
11
|
@connection = options[:connection] || ApiConnection
|
12
12
|
end
|
13
13
|
|
14
14
|
def send_request(path, method, params = {})
|
15
15
|
raise NotAuthenticated unless valid?
|
16
|
-
connection = @connection.new(enviroment)
|
16
|
+
connection = @connection.new(enviroment,api_version_header)
|
17
17
|
connection.authenticate(@app_id, @app_password)
|
18
18
|
connection.create(path, method, params)
|
19
19
|
end
|
@@ -27,6 +27,15 @@ module Espago
|
|
27
27
|
production ? "https://secure.espago.com/api" : "https://sandbox.espago.com/api"
|
28
28
|
end
|
29
29
|
|
30
|
+
def api_version_header
|
31
|
+
if @api_version.to_s == '3'
|
32
|
+
{'Accept' => "application/vnd.espago.v3+json"}
|
33
|
+
else
|
34
|
+
{'Accept' => "application/vnd.espago.v2+json"}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
|
30
39
|
def valid?
|
31
40
|
@app_id && @app_password
|
32
41
|
end
|
data/lib/espago/router.rb
CHANGED
data/lib/espago/version.rb
CHANGED
@@ -4,7 +4,7 @@ require "json"
|
|
4
4
|
|
5
5
|
class StubbedResponse < Struct.new(:body, :status); end
|
6
6
|
|
7
|
-
class Espago::ApiConnection::
|
7
|
+
class Espago::ApiConnection::PathStubbed
|
8
8
|
def initialize(connection); end
|
9
9
|
|
10
10
|
def request(params = {})
|
@@ -12,7 +12,7 @@ class Espago::ApiConnection::StubbedPath
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
class Espago::ApiConnection::
|
15
|
+
class Espago::ApiConnection::PathUnauthorized
|
16
16
|
def initialize(connection)
|
17
17
|
end
|
18
18
|
|
@@ -21,8 +21,9 @@ class Espago::ApiConnection::UnauthorizedPath
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
|
24
25
|
describe Espago::ApiConnection do
|
25
|
-
subject { Espago::ApiConnection.new("http://some.api.example.com") }
|
26
|
+
subject { Espago::ApiConnection.new("http://some.api.example.com",{'Accept' => "application/vnd.espago.v2+json"}) }
|
26
27
|
|
27
28
|
context "#create" do
|
28
29
|
it "returns response" do
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "espago/back_request"
|
3
|
+
require "json"
|
4
|
+
|
5
|
+
|
6
|
+
describe Espago::BackRequest do
|
7
|
+
subject { Espago::BackRequest.new(response)}
|
8
|
+
let(:response) {
|
9
|
+
{"id"=>"in_tUCMhwlg2nkvAaL",
|
10
|
+
"date"=>"1417030496",
|
11
|
+
"client"=>"cli_90Pi6Jf0ndl_PP",
|
12
|
+
"subscription"=>"sub_8yYuCBKdywr7e2",
|
13
|
+
"amount"=>"123.45",
|
14
|
+
"currency"=>"pln",
|
15
|
+
"paid"=>"true",
|
16
|
+
"issuer_response_code"=>"00",
|
17
|
+
"attempts"=>"1",
|
18
|
+
"next_payment_attempt"=>"",
|
19
|
+
"created_at"=>1417030497
|
20
|
+
}
|
21
|
+
}
|
22
|
+
|
23
|
+
its(:id) { should eq("in_tUCMhwlg2nkvAaL") }
|
24
|
+
its(:subscription) { should eq("sub_8yYuCBKdywr7e2") }
|
25
|
+
its(:amount) { should eq("123.45") }
|
26
|
+
its(:currency) { should eq("pln") }
|
27
|
+
its(:paid) { should eq("true") }
|
28
|
+
its(:client) { should eq("cli_90Pi6Jf0ndl_PP") }
|
29
|
+
its(:created_at) { should eq(Time.at(1417030497)) }
|
30
|
+
its(:card) { should eq({}) }
|
31
|
+
its(:imaginated_attribute) { should be_nil }
|
32
|
+
|
33
|
+
end
|
data/spec/espago/client_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'espago/client'
|
|
3
3
|
require "helpers/fake_response"
|
4
4
|
|
5
5
|
class StubbedApiConnection
|
6
|
-
def initialize(enviroment); end
|
6
|
+
def initialize(enviroment,headers); end
|
7
7
|
def authenticate(app_id, app_password); end
|
8
8
|
def create(path, method, params= {})
|
9
9
|
'returned api data'
|
@@ -11,13 +11,14 @@ class StubbedApiConnection
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe Espago::Client do
|
14
|
-
subject { Espago::Client.new( app_id: '
|
14
|
+
subject { Espago::Client.new( app_id: 'app_id_test', app_password: 'secret', connection: stubbed_api_connection, api_version: 2) }
|
15
15
|
let(:stubbed_api_connection) { StubbedApiConnection }
|
16
16
|
let(:response) { FakeResponse.new(200, {id: 1, status: "2012"}.to_json) }
|
17
17
|
|
18
18
|
it { subject.should respond_to :app_id }
|
19
19
|
it { subject.should respond_to :app_password }
|
20
20
|
it { subject.should respond_to :public_key }
|
21
|
+
it { subject.should respond_to :api_version }
|
21
22
|
|
22
23
|
context "#send_request" do
|
23
24
|
let(:method) { :get }
|
data/spec/espago/router_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "espago/router"
|
3
3
|
|
4
|
-
class Espago::ApiConnection::
|
4
|
+
class Espago::ApiConnection::StubbedRequestGet; end
|
5
5
|
|
6
6
|
describe Espago::Router do
|
7
7
|
subject { Espago::Router.new(:stubbed_request, :get) }
|
@@ -11,7 +11,7 @@ describe Espago::Router do
|
|
11
11
|
|
12
12
|
context "#route" do
|
13
13
|
it "should get a class name depending on path and method" do
|
14
|
-
subject.route.should eq( Espago::ApiConnection::
|
14
|
+
subject.route.should eq( Espago::ApiConnection::StubbedRequestGet )
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should raise error if class not found" do
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe 'Two api headers test' do
|
4
|
+
|
5
|
+
it "API v.2" do
|
6
|
+
Espago.api_version = '2'
|
7
|
+
VCR.use_cassette('api 2') do
|
8
|
+
response = Espago.charges :get
|
9
|
+
response.count.should eq(596)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "API v.3" do
|
14
|
+
Espago.api_version = '3'
|
15
|
+
VCR.use_cassette('api 3') do
|
16
|
+
response = Espago.charges :get
|
17
|
+
response.count.should eq(596)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|