mollie-api-ruby 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,55 +4,55 @@ require 'sinatra'
4
4
  # Show all examples as links.
5
5
  #
6
6
  examples = [
7
- '1-new-payment',
8
- '2-webhook-verification',
9
- '3-return-page',
10
- '4-ideal-payment',
11
- '5-payments-history',
12
- '6-list-activated-methods',
13
- '7-refund-payment'
7
+ '1-new-payment',
8
+ '2-webhook-verification',
9
+ '3-return-page',
10
+ '4-ideal-payment',
11
+ '5-payments-history',
12
+ '6-list-activated-methods',
13
+ '7-refund-payment'
14
14
  ]
15
15
 
16
16
  get "/" do
17
- index = ""
17
+ index = ""
18
18
 
19
- examples.each { |example|
20
- index << "<a href='/#{example}'>#{example}</a><br>"
21
- }
19
+ examples.each { |example|
20
+ index << "<a href='/#{example}'>#{example}</a><br>"
21
+ }
22
22
 
23
- index
23
+ index
24
24
  end
25
25
 
26
26
  #
27
27
  # Register all examples as pages.
28
28
  #
29
29
  examples.each { |example|
30
- get "/#{example}" do
31
- $request = request
32
- $response = response
33
- load File.expand_path "#{example}.rb", File.dirname(__FILE__)
34
- end
35
-
36
- post "/#{example}" do
37
- $request = request
38
- $response = response
39
- load File.expand_path "#{example}.rb", File.dirname(__FILE__)
40
- end
30
+ get "/#{example}" do
31
+ $request = request
32
+ $response = response
33
+ load File.expand_path "#{example}.rb", File.dirname(__FILE__)
34
+ end
35
+
36
+ post "/#{example}" do
37
+ $request = request
38
+ $response = response
39
+ load File.expand_path "#{example}.rb", File.dirname(__FILE__)
40
+ end
41
41
  }
42
42
 
43
43
  #
44
44
  # NOTE: This example uses a text file as a database. Please use a real database like MySQL in production code.
45
45
  #
46
46
  def database_write (order_id, status)
47
- order_id = order_id.to_i
48
- database = File.expand_path "orders/order-#{order_id}.txt", File.dirname(__FILE__)
47
+ order_id = order_id.to_i
48
+ database = File.expand_path "orders/order-#{order_id}.txt", File.dirname(__FILE__)
49
49
 
50
- File.open(database, 'w') { |file| file.write status }
50
+ File.open(database, 'w') { |file| file.write status }
51
51
  end
52
52
 
53
53
  def database_read (order_id)
54
- order_id = order_id.to_i
55
- database = File.expand_path "orders/order-#{order_id}.txt", File.dirname(__FILE__)
54
+ order_id = order_id.to_i
55
+ database = File.expand_path "orders/order-#{order_id}.txt", File.dirname(__FILE__)
56
56
 
57
- status = File.read(database) || "unknown order"
58
- end
57
+ status = File.read(database) || "unknown order"
58
+ end
@@ -15,96 +15,96 @@ require "rest_client"
15
15
  "Object/Method"].each {|file| require File.expand_path file, File.dirname(__FILE__) }
16
16
 
17
17
  module Mollie
18
- module API
19
- class Client
20
- CLIENT_VERSION = "1.1.2"
21
- API_ENDPOINT = "https://api.mollie.nl"
22
- API_VERSION = "v1"
23
-
24
- attr_reader :payments, :issuers, :methods, :payments_refunds
25
-
26
- def initialize ()
27
- @payments = Mollie::API::Resource::Payments.new self
28
- @issuers = Mollie::API::Resource::Issuers.new self
29
- @methods = Mollie::API::Resource::Methods.new self
30
- @payments_refunds = Mollie::API::Resource::Payments::Refunds.new self
31
-
32
- @api_endpoint = API_ENDPOINT
33
- @api_key = ""
34
- @version_strings = []
35
-
36
- addVersionString "Mollie/" << CLIENT_VERSION
37
- addVersionString "Ruby/" << RUBY_VERSION
38
- addVersionString OpenSSL::OPENSSL_VERSION.split(" ").slice(0, 2).join "/"
39
- end
40
-
41
- def setApiEndpoint (api_endpoint)
42
- @api_endpoint = api_endpoint.chomp "/"
43
- end
44
-
45
- def getApiEndpoint ()
46
- @api_endpoint
47
- end
48
-
49
- def setApiKey (api_key)
50
- @api_key = api_key
51
- end
52
-
53
- def addVersionString (version_string)
54
- @version_strings << (version_string.gsub /\s+/, "-")
55
- end
56
-
57
- def _getRestClient (request_url, request_headers)
58
- RestClient::Resource.new request_url,
59
- :headers => request_headers,
60
- :ssl_ca_file => (File.expand_path "cacert.pem", File.dirname(__FILE__)),
61
- :verify_ssl => OpenSSL::SSL::VERIFY_PEER
62
- end
63
-
64
- def performHttpCall (http_method, api_method, id = nil, http_body = nil)
65
- request_headers = {
66
- :accept => :json,
67
- :authorization => "Bearer #{@api_key}",
68
- :user_agent => @version_strings.join(" "),
69
- "X-Mollie-Client-Info" => getUname
70
- }
71
-
72
- if http_body.respond_to? :delete_if
73
- http_body.delete_if { |k, v| v.nil? }
74
- end
75
-
76
- begin
77
- request_url = "#{@api_endpoint}/#{API_VERSION}/#{api_method}/#{id}".chomp "/"
78
- rest_client = _getRestClient request_url, request_headers
79
-
80
- case http_method
81
- when "GET"
82
- response = rest_client.get
83
- when "POST"
84
- response = rest_client.post http_body
85
- when "DELETE"
86
- response = rest_client.delete
87
- end
88
- response = JSON.parse response, :symbolize_names => true
89
- rescue RestClient::ExceptionWithResponse => e
90
- response = JSON.parse e.response, :symbolize_names => true
91
- raise e if response[:error].nil?
92
- end
93
-
94
- unless response[:error].nil?
95
- exception = Mollie::API::Exception.new response[:error][:message]
96
- exception.field = response[:error][:field] unless response[:error][:field].nil?
97
- raise exception
98
- end
99
-
100
- response
101
- end
102
-
103
- def getUname ()
104
- `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
105
- rescue Errno::ENOMEM
106
- "uname lookup failed"
107
- end
108
- end
109
- end
18
+ module API
19
+ class Client
20
+ CLIENT_VERSION = "1.1.3"
21
+ API_ENDPOINT = "https://api.mollie.nl"
22
+ API_VERSION = "v1"
23
+
24
+ attr_reader :payments, :issuers, :methods, :payments_refunds
25
+
26
+ def initialize
27
+ @payments = Mollie::API::Resource::Payments.new self
28
+ @issuers = Mollie::API::Resource::Issuers.new self
29
+ @methods = Mollie::API::Resource::Methods.new self
30
+ @payments_refunds = Mollie::API::Resource::Payments::Refunds.new self
31
+
32
+ @api_endpoint = API_ENDPOINT
33
+ @api_key = ""
34
+ @version_strings = []
35
+
36
+ addVersionString "Mollie/" << CLIENT_VERSION
37
+ addVersionString "Ruby/" << RUBY_VERSION
38
+ addVersionString OpenSSL::OPENSSL_VERSION.split(" ").slice(0, 2).join "/"
39
+ end
40
+
41
+ def setApiEndpoint(api_endpoint)
42
+ @api_endpoint = api_endpoint.chomp "/"
43
+ end
44
+
45
+ def getApiEndpoint
46
+ @api_endpoint
47
+ end
48
+
49
+ def setApiKey(api_key)
50
+ @api_key = api_key
51
+ end
52
+
53
+ def addVersionString(version_string)
54
+ @version_strings << (version_string.gsub /\s+/, "-")
55
+ end
56
+
57
+ def _getRestClient(request_url, request_headers)
58
+ RestClient::Resource.new request_url,
59
+ :headers => request_headers,
60
+ :ssl_ca_file => (File.expand_path "cacert.pem", File.dirname(__FILE__)),
61
+ :verify_ssl => OpenSSL::SSL::VERIFY_PEER
62
+ end
63
+
64
+ def performHttpCall(http_method, api_method, id = nil, http_body = nil)
65
+ request_headers = {
66
+ :accept => :json,
67
+ :authorization => "Bearer #{@api_key}",
68
+ :user_agent => @version_strings.join(" "),
69
+ "X-Mollie-Client-Info" => getUname
70
+ }
71
+
72
+ if http_body.respond_to? :delete_if
73
+ http_body.delete_if { |k, v| v.nil? }
74
+ end
75
+
76
+ begin
77
+ request_url = "#{@api_endpoint}/#{API_VERSION}/#{api_method}/#{id}".chomp "/"
78
+ rest_client = _getRestClient request_url, request_headers
79
+
80
+ case http_method
81
+ when "GET"
82
+ response = rest_client.get
83
+ when "POST"
84
+ response = rest_client.post http_body
85
+ when "DELETE"
86
+ response = rest_client.delete
87
+ end
88
+ response = JSON.parse response, :symbolize_names => true
89
+ rescue RestClient::ExceptionWithResponse => e
90
+ response = JSON.parse e.response, :symbolize_names => true
91
+ raise e if response[:error].nil?
92
+ end
93
+
94
+ unless response[:error].nil?
95
+ exception = Mollie::API::Exception.new response[:error][:message]
96
+ exception.field = response[:error][:field] unless response[:error][:field].nil?
97
+ raise exception
98
+ end
99
+
100
+ response
101
+ end
102
+
103
+ def getUname
104
+ `uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
105
+ rescue Errno::ENOMEM
106
+ "uname lookup failed"
107
+ end
108
+ end
109
+ end
110
110
  end
@@ -1,9 +1,9 @@
1
1
  module Mollie
2
- module API
3
- class Exception < StandardError
4
- @field = nil
2
+ module API
3
+ class Exception < StandardError
4
+ @field = nil
5
5
 
6
- attr_accessor :field
7
- end
8
- end
6
+ attr_accessor :field
7
+ end
8
+ end
9
9
  end
@@ -1,18 +1,18 @@
1
1
  module Mollie
2
- module API
3
- module Object
4
- class Base
5
- def initialize (hash)
6
- hash.each { |key, value|
7
- if value.respond_to? :each
8
- value = Base.new value
9
- end
2
+ module API
3
+ module Object
4
+ class Base
5
+ def initialize(hash)
6
+ hash.each { |key, value|
7
+ if value.respond_to? :each
8
+ value = Base.new value
9
+ end
10
10
 
11
- instance_variable_set "@#{key}", value
12
- self.class.send :attr_accessor, key
13
- }
14
- end
15
- end
16
- end
17
- end
11
+ instance_variable_set "@#{key}", value
12
+ self.class.send :attr_accessor, key
13
+ }
14
+ end
15
+ end
16
+ end
17
+ end
18
18
  end
@@ -1,11 +1,11 @@
1
1
  module Mollie
2
- module API
3
- module Object
4
- class Issuer < Base
5
- attr_accessor :id,
6
- :name,
7
- :method
8
- end
9
- end
10
- end
11
- end
2
+ module API
3
+ module Object
4
+ class Issuer < Base
5
+ attr_accessor :id,
6
+ :name,
7
+ :method
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,35 +1,35 @@
1
1
  module Mollie
2
- module API
3
- module Object
4
- class List < Base
5
- include Enumerable
2
+ module API
3
+ module Object
4
+ class List < Base
5
+ include Enumerable
6
6
 
7
- attr_accessor :totalCount,
8
- :offset,
9
- :count,
10
- :data
7
+ attr_accessor :totalCount,
8
+ :offset,
9
+ :count,
10
+ :data
11
11
 
12
- def initialize (hash, classResourceObject)
13
- data = hash[:data] || []
14
- hash[:data] = nil
15
- super hash
12
+ def initialize(hash, classResourceObject)
13
+ data = hash[:data] || []
14
+ hash[:data] = nil
15
+ super hash
16
16
 
17
- @data = []
18
- data.each { |hash|
19
- @data << (classResourceObject.new hash)
20
- }
21
- end
17
+ @data = []
18
+ data.each { |hash|
19
+ @data << (classResourceObject.new hash)
20
+ }
21
+ end
22
22
 
23
- def each (&block)
24
- @data.each { |object|
25
- if block_given?
26
- block.call object
27
- else
28
- yield object
29
- end
30
- }
31
- end
32
- end
33
- end
34
- end
35
- end
23
+ def each(&block)
24
+ @data.each { |object|
25
+ if block_given?
26
+ block.call object
27
+ else
28
+ yield object
29
+ end
30
+ }
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,29 +1,29 @@
1
1
  module Mollie
2
- module API
3
- module Object
4
- class Method < Base
5
- IDEAL = "ideal"
6
- CREDITCARD = "creditcard"
7
- MISTERCASH = "mistercash"
8
- BANKTRANSFER = "banktransfer"
9
- PAYPAL = "paypal"
10
- PAYSAFECARD = "paysafecard"
11
- BITCOIN = "bitcoin"
12
- SOFORT = "sofort"
2
+ module API
3
+ module Object
4
+ class Method < Base
5
+ IDEAL = "ideal"
6
+ CREDITCARD = "creditcard"
7
+ MISTERCASH = "mistercash"
8
+ BANKTRANSFER = "banktransfer"
9
+ PAYPAL = "paypal"
10
+ PAYSAFECARD = "paysafecard"
11
+ BITCOIN = "bitcoin"
12
+ SOFORT = "sofort"
13
13
 
14
- attr_accessor :id,
15
- :description,
16
- :amount,
17
- :image
14
+ attr_accessor :id,
15
+ :description,
16
+ :amount,
17
+ :image
18
18
 
19
- def getMinimumAmount ()
20
- @amount.minimum
21
- end
19
+ def getMinimumAmount
20
+ @amount.minimum
21
+ end
22
22
 
23
- def getMaximumAmount ()
24
- @amount.maximum
25
- end
26
- end
27
- end
28
- end
23
+ def getMaximumAmount
24
+ @amount.maximum
25
+ end
26
+ end
27
+ end
28
+ end
29
29
  end