paymill 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,4 +2,5 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rspec"
5
+ gem "rspec"
6
+ gem "rake"
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Paymill
1
+ Paymill ![Build status](http://travis-ci.org/dkd/paymill-ruby.png)
2
2
  ======
3
3
 
4
4
  This is a Ruby wrapper for Paymill's API.
data/lib/paymill.rb CHANGED
@@ -16,6 +16,7 @@ module Paymill
16
16
 
17
17
  module Operations
18
18
  autoload :Create, "paymill/operations/create"
19
+ autoload :Delete, "paymill/operations/delete"
19
20
  autoload :Find, "paymill/operations/find"
20
21
  end
21
22
 
@@ -34,7 +35,7 @@ module Paymill
34
35
  @@api_key = api_key
35
36
  end
36
37
 
37
- def request(http_method, api_url, data, path="")
38
+ def request(http_method, api_url, data)
38
39
  raise AuthenticationError if api_key.nil?
39
40
 
40
41
  https = Net::HTTP.new(API_BASE, Net::HTTP.https_default_port)
@@ -42,15 +43,18 @@ module Paymill
42
43
  https.verify_mode = OpenSSL::SSL::VERIFY_PEER
43
44
  https.ca_file = File.join(File.dirname(__FILE__), "data/paymill.crt")
44
45
  https.start do |connection|
45
- url = case http_method
46
+ url = "/v1/#{api_url}"
47
+ https_request = case http_method
46
48
  when :post
47
- Net::HTTP::Post.new("/v1/#{api_url}#{path}")
49
+ Net::HTTP::Post.new(url)
50
+ when :delete
51
+ Net::HTTP::Delete.new(url)
48
52
  else
49
- Net::HTTP::Get.new("/v1/#{api_url}#{path}")
53
+ Net::HTTP::Get.new(url)
50
54
  end
51
- url.basic_auth(api_key,"")
52
- url.set_form_data(data) if http_method == :post
53
- @response = https.request(url)
55
+ https_request.basic_auth(api_key,"")
56
+ https_request.set_form_data(data) if http_method == :post
57
+ @response = https.request(https_request)
54
58
  end
55
59
  raise AuthenticationError if @response.code.to_i == 401
56
60
  raise APIError if @response.code.to_i >= 500
@@ -1,6 +1,7 @@
1
1
  module Paymill
2
2
  class Client
3
3
  include Paymill::Operations::Create
4
+ include Paymill::Operations::Delete
4
5
  include Paymill::Operations::Find
5
6
 
6
7
  attr_accessor :id, :email, :description, :attributes, :created_at,
data/lib/paymill/offer.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  module Paymill
2
2
  class Offer
3
3
  include Paymill::Operations::Create
4
+ include Paymill::Operations::Delete
4
5
  include Paymill::Operations::Find
5
6
 
6
7
  attr_accessor :id, :name, :amount, :interval, :trial_period_days, :currency
@@ -0,0 +1,16 @@
1
+ module Paymill
2
+ module Operations
3
+ module Delete
4
+ module ClassMethods
5
+ def delete(id)
6
+ response = Paymill.request(:delete, "#{self.name.split("::").last.downcase}s/#{id}", {})
7
+ true
8
+ end
9
+ end
10
+
11
+ def self.included(base)
12
+ base.extend(ClassMethods)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,7 +3,7 @@ module Paymill
3
3
  module Find
4
4
  module ClassMethods
5
5
  def find(id)
6
- response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s", {}, "/#{id}")
6
+ response = Paymill.request(:get, "#{self.name.split("::").last.downcase}s/#{id}", {})
7
7
  self.new(response["data"])
8
8
  end
9
9
  end
@@ -1,6 +1,7 @@
1
1
  module Paymill
2
2
  class Subscription
3
3
  include Paymill::Operations::Create
4
+ include Paymill::Operations::Delete
4
5
  include Paymill::Operations::Find
5
6
 
6
7
  attr_accessor :id, :plan, :livemode, :cancel_at_period_end, :created_at, :updated_at,
@@ -1,3 +1,3 @@
1
1
  module Paymill
2
- VERSION = "0.0.1"
3
- end
2
+ VERSION = "0.0.2"
3
+ end
@@ -18,11 +18,18 @@ describe Paymill::Client do
18
18
 
19
19
  describe ".find" do
20
20
  it "makes a new GET request using the correct API endpoint" do
21
- Paymill.should_receive(:request).with(:get, "clients", {}, "/123").and_return("data" => {})
21
+ Paymill.should_receive(:request).with(:get, "clients/123", {}).and_return("data" => {})
22
22
  Paymill::Client.find("123")
23
23
  end
24
24
  end
25
25
 
26
+ describe ".delete" do
27
+ it "makes a new DELETE request using the correct API endpoint" do
28
+ Paymill.should_receive(:request).with(:delete, "clients/123", {}).and_return(true)
29
+ Paymill::Client.delete("123")
30
+ end
31
+ end
32
+
26
33
  describe ".create" do
27
34
  it "makes a new POST request using the correct API endpoint" do
28
35
  Paymill.should_receive(:request).with(:post, "clients", valid_attributes).and_return("data" => {})
@@ -25,11 +25,18 @@ describe Paymill::Offer do
25
25
 
26
26
  describe ".find" do
27
27
  it "makes a new GET request using the correct API endpoint" do
28
- Paymill.should_receive(:request).with(:get, "offers", {}, "/123").and_return("data" => {})
28
+ Paymill.should_receive(:request).with(:get, "offers/123", {}).and_return("data" => {})
29
29
  Paymill::Offer.find("123")
30
30
  end
31
31
  end
32
32
 
33
+ describe ".delete" do
34
+ it "makes a new DELETE request using the correct API endpoint" do
35
+ Paymill.should_receive(:request).with(:delete, "offers/123", {}).and_return(true)
36
+ Paymill::Offer.delete("123")
37
+ end
38
+ end
39
+
33
40
  describe ".create" do
34
41
  it "makes a new POST request using the correct API endpoint" do
35
42
  Paymill.should_receive(:request).with(:post, "offers", valid_attributes).and_return("data" => {})
@@ -33,11 +33,18 @@ describe Paymill::Subscription do
33
33
 
34
34
  describe ".find" do
35
35
  it "makes a new GET request using the correct API endpoint" do
36
- Paymill.should_receive(:request).with(:get, "subscriptions", {}, "/123").and_return("data" => {})
36
+ Paymill.should_receive(:request).with(:get, "subscriptions/123", {}).and_return("data" => {})
37
37
  Paymill::Subscription.find("123")
38
38
  end
39
39
  end
40
40
 
41
+ describe ".delete" do
42
+ it "makes a new DELETE request using the correct API endpoint" do
43
+ Paymill.should_receive(:request).with(:delete, "subscriptions/123", {}).and_return(true)
44
+ Paymill::Subscription.delete("123")
45
+ end
46
+ end
47
+
41
48
  describe ".create" do
42
49
  it "makes a new POST request using the correct API endpoint" do
43
50
  Paymill.should_receive(:request).with(:post, "subscriptions", valid_attributes).and_return("data" => {})
@@ -33,7 +33,7 @@ describe Paymill::Transaction do
33
33
 
34
34
  describe ".find" do
35
35
  it "makes a new GET request using the correct API endpoint" do
36
- Paymill.should_receive(:request).with(:get, "transactions", {}, "/123").and_return("data" => {})
36
+ Paymill.should_receive(:request).with(:get, "transactions/123", {}).and_return("data" => {})
37
37
  Paymill::Transaction.find("123")
38
38
  end
39
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-16 00:00:00.000000000 Z
12
+ date: 2012-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &2152735480 !ruby/object:Gem::Requirement
16
+ requirement: &2163953000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152735480
24
+ version_requirements: *2163953000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2152745780 !ruby/object:Gem::Requirement
27
+ requirement: &2163924640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2152745780
35
+ version_requirements: *2163924640
36
36
  description: API wrapper for Paymill.
37
37
  email:
38
38
  - stefan.sprenger@dkd.de
@@ -52,6 +52,7 @@ files:
52
52
  - lib/paymill/credit_card.rb
53
53
  - lib/paymill/offer.rb
54
54
  - lib/paymill/operations/create.rb
55
+ - lib/paymill/operations/delete.rb
55
56
  - lib/paymill/operations/find.rb
56
57
  - lib/paymill/subscription.rb
57
58
  - lib/paymill/transaction.rb
@@ -76,12 +77,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  - - ! '>='
77
78
  - !ruby/object:Gem::Version
78
79
  version: '0'
80
+ segments:
81
+ - 0
82
+ hash: -2942801936658409204
79
83
  required_rubygems_version: !ruby/object:Gem::Requirement
80
84
  none: false
81
85
  requirements:
82
86
  - - ! '>='
83
87
  - !ruby/object:Gem::Version
84
88
  version: '0'
89
+ segments:
90
+ - 0
91
+ hash: -2942801936658409204
85
92
  requirements: []
86
93
  rubyforge_project:
87
94
  rubygems_version: 1.8.10
@@ -96,4 +103,3 @@ test_files:
96
103
  - spec/paymill/transaction_spec.rb
97
104
  - spec/paymill_spec.rb
98
105
  - spec/spec_helper.rb
99
- has_rdoc: