Recharge 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/charge.rb +1 -1
- data/examples/test.rb +25 -0
- data/lib/recharge/base.rb +6 -6
- data/lib/recharge/charge.rb +10 -10
- data/lib/recharge/client.rb +15 -6
- data/lib/recharge/customer.rb +10 -10
- data/lib/recharge/paymethod.rb +4 -4
- data/lib/recharge/product.rb +10 -10
- data/lib/recharge/transaction.rb +6 -6
- metadata +5 -4
data/examples/charge.rb
CHANGED
@@ -8,7 +8,7 @@ require 'recharge'
|
|
8
8
|
|
9
9
|
# Set your API key here, found in Recharge Settings > API Settings > API Private Key
|
10
10
|
# If incorrect or blank, any calls will raise a Response::NotAuthorized
|
11
|
-
Recharge.api_key = "
|
11
|
+
Recharge.api_key = "14a1a867f39b4fdced2148871e4e542015cad979"
|
12
12
|
|
13
13
|
|
14
14
|
|
data/examples/test.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Examples for the Recharge API Gem
|
2
|
+
# Charge Resource
|
3
|
+
|
4
|
+
# Only 2 lines are required to get started:
|
5
|
+
# Require the recharge gem
|
6
|
+
require 'rubygems'
|
7
|
+
require 'recharge'
|
8
|
+
|
9
|
+
# Set your API key here, found in Recharge Settings > API Settings > API Private Key
|
10
|
+
# If incorrect or blank, any calls will raise a Response::NotAuthorized
|
11
|
+
Recharge.api_key = "14a1a867f39b4fdced2148871e4e542015cad979"
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
# deletes an existing product
|
16
|
+
puts "", "Delete Product"
|
17
|
+
|
18
|
+
begin
|
19
|
+
# find the product first
|
20
|
+
product = Recharge::Product.find('pr4f3192260b55d', 'APIKEY')
|
21
|
+
# call destroy on it to delete it
|
22
|
+
product.destroy('APIKEY')
|
23
|
+
rescue Exception => e
|
24
|
+
puts ">> error #{e.message}"
|
25
|
+
end
|
data/lib/recharge/base.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Recharge
|
2
2
|
class Base
|
3
3
|
class << self
|
4
|
-
def get(uri)
|
4
|
+
def get(uri, apiKey=nil)
|
5
5
|
client = Client.new()
|
6
|
-
return client.request('GET', uri)
|
6
|
+
return client.request('GET', uri, nil, apiKey)
|
7
7
|
end
|
8
8
|
|
9
|
-
def post(uri, data=nil)
|
9
|
+
def post(uri, data=nil, apiKey=nil)
|
10
10
|
client = Client.new()
|
11
|
-
return client.request('POST', uri, data)
|
11
|
+
return client.request('POST', uri, data, apiKey)
|
12
12
|
end
|
13
13
|
|
14
|
-
def delete(uri)
|
14
|
+
def delete(uri, apiKey=nil)
|
15
15
|
client = Client.new()
|
16
|
-
return client.request('DELETE', uri)
|
16
|
+
return client.request('DELETE', uri, nil, apiKey)
|
17
17
|
end
|
18
18
|
|
19
19
|
def returnImportantXML(data)
|
data/lib/recharge/charge.rb
CHANGED
@@ -22,24 +22,24 @@ module Recharge
|
|
22
22
|
def initialize(id='')
|
23
23
|
@id = id
|
24
24
|
end
|
25
|
-
def self.find_all
|
26
|
-
responseXML = Recharge::Base.get('charges')
|
25
|
+
def self.find_all (apiKey=nil)
|
26
|
+
responseXML = Recharge::Base.get('charges', apiKey)
|
27
27
|
parse(responseXML.to_s)
|
28
28
|
end
|
29
|
-
def self.find (id)
|
30
|
-
responseXML = Recharge::Base.get('charges/'+id)
|
29
|
+
def self.find (id, apiKey=nil)
|
30
|
+
responseXML = Recharge::Base.get('charges/'+id, apiKey)
|
31
31
|
parse(responseXML.to_s)
|
32
32
|
end
|
33
|
-
def self.create (attributes = {})
|
34
|
-
responseXML = Recharge::Base.post('charges', attributes)
|
33
|
+
def self.create (attributes = {}, apiKey=nil)
|
34
|
+
responseXML = Recharge::Base.post('charges', attributes, apiKey)
|
35
35
|
parse(responseXML.to_s)
|
36
36
|
end
|
37
|
-
def update (attributes = {})
|
38
|
-
responseXML = Recharge::Base.post('charges/'+self.id, attributes)
|
37
|
+
def update (attributes = {}, apiKey=nil)
|
38
|
+
responseXML = Recharge::Base.post('charges/'+self.id, attributes, apiKey)
|
39
39
|
Charge.parse(responseXML.to_s)
|
40
40
|
end
|
41
|
-
def destroy
|
42
|
-
responseXML = Recharge::Base.delete('charges/'+self.id)
|
41
|
+
def destroy (apiKey=nil)
|
42
|
+
responseXML = Recharge::Base.delete('charges/'+self.id, apiKey)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
data/lib/recharge/client.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
class Client
|
2
2
|
|
3
|
+
class NotAuthorized < StandardError
|
4
|
+
end
|
5
|
+
|
3
6
|
def baseURL
|
4
7
|
"https://www.rechargebilling.com/API/v2/"
|
5
8
|
end
|
6
9
|
|
7
|
-
def request(method, uri, data=nil)
|
8
|
-
response = sendRequest(method, uri, data)
|
10
|
+
def request(method, uri, data=nil, apiKey=nil)
|
11
|
+
response = sendRequest(method, uri, data, apiKey)
|
9
12
|
response.assertValidResponse
|
10
13
|
if response.code.to_i == 200
|
11
14
|
if method != "DELETE"
|
@@ -19,13 +22,19 @@ class Client
|
|
19
22
|
|
20
23
|
end
|
21
24
|
|
22
|
-
def sendRequest(method, uri, data=nil)
|
25
|
+
def sendRequest(method, uri, data=nil, apiKey=nil)
|
23
26
|
require "net/https"
|
24
27
|
require "uri"
|
25
28
|
|
26
29
|
if !Recharge.api_key
|
27
|
-
|
28
|
-
|
30
|
+
if !apiKey
|
31
|
+
raise NotAuthorized, "No API Key"
|
32
|
+
return
|
33
|
+
end
|
34
|
+
else
|
35
|
+
if !apiKey
|
36
|
+
apiKey = Recharge.api_key
|
37
|
+
end
|
29
38
|
end
|
30
39
|
|
31
40
|
uri = baseURL+uri
|
@@ -44,7 +53,7 @@ class Client
|
|
44
53
|
request = Net::HTTP::Delete.new(uri.request_uri)
|
45
54
|
end
|
46
55
|
|
47
|
-
request.basic_auth(
|
56
|
+
request.basic_auth(apiKey, "")
|
48
57
|
|
49
58
|
http = Net::HTTP.new(uri.host, uri.port)
|
50
59
|
http.use_ssl = true
|
data/lib/recharge/customer.rb
CHANGED
@@ -30,24 +30,24 @@ module Recharge
|
|
30
30
|
def initialize(id='')
|
31
31
|
@id = id
|
32
32
|
end
|
33
|
-
def self.find_all
|
34
|
-
responseXML = Recharge::Base.get('customers')
|
33
|
+
def self.find_all (apiKey=nil)
|
34
|
+
responseXML = Recharge::Base.get('customers', apiKey)
|
35
35
|
parse(responseXML.to_s)
|
36
36
|
end
|
37
|
-
def self.find (id)
|
38
|
-
responseXML = Recharge::Base.get('customers/'+id)
|
37
|
+
def self.find (id, apiKey=nil)
|
38
|
+
responseXML = Recharge::Base.get('customers/'+id, apiKey)
|
39
39
|
parse(responseXML.to_s)
|
40
40
|
end
|
41
|
-
def self.create (attributes = {})
|
42
|
-
responseXML = Recharge::Base.post('customers', attributes)
|
41
|
+
def self.create (attributes = {}, apiKey=nil)
|
42
|
+
responseXML = Recharge::Base.post('customers', attributes, apiKey)
|
43
43
|
parse(responseXML.to_s)
|
44
44
|
end
|
45
|
-
def update (attributes = {})
|
46
|
-
responseXML = Recharge::Base.post('customers/'+self.id, attributes)
|
45
|
+
def update (attributes = {}, apiKey=nil)
|
46
|
+
responseXML = Recharge::Base.post('customers/'+self.id, attributes, apiKey)
|
47
47
|
Customer.parse(responseXML.to_s)
|
48
48
|
end
|
49
|
-
def destroy
|
50
|
-
responseXML = Recharge::Base.delete('customers/'+self.id)
|
49
|
+
def destroy (apiKey=nil)
|
50
|
+
responseXML = Recharge::Base.delete('customers/'+self.id, apiKey)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
data/lib/recharge/paymethod.rb
CHANGED
@@ -12,12 +12,12 @@ module Recharge
|
|
12
12
|
element :nameOnCard, String
|
13
13
|
element :error, String
|
14
14
|
|
15
|
-
def self.create (attributes = {})
|
16
|
-
responseXML = Recharge::Base.post('paymethods', attributes)
|
15
|
+
def self.create (attributes = {}, apiKey=nil)
|
16
|
+
responseXML = Recharge::Base.post('paymethods', attributes, apiKey)
|
17
17
|
parse(responseXML.to_s)
|
18
18
|
end
|
19
|
-
def self.destroy (id)
|
20
|
-
responseXML = Recharge::Base.delete('paymethods/'+id)
|
19
|
+
def self.destroy (id, apiKey=nil)
|
20
|
+
responseXML = Recharge::Base.delete('paymethods/'+id, apiKey)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
data/lib/recharge/product.rb
CHANGED
@@ -14,24 +14,24 @@ module Recharge
|
|
14
14
|
def initialize(id='')
|
15
15
|
@id = id
|
16
16
|
end
|
17
|
-
def self.find_all
|
18
|
-
responseXML = Recharge::Base.get('products')
|
17
|
+
def self.find_all (apiKey=nil)
|
18
|
+
responseXML = Recharge::Base.get('products', apiKey)
|
19
19
|
parse(responseXML.to_s)
|
20
20
|
end
|
21
|
-
def self.find (id)
|
22
|
-
responseXML = Recharge::Base.get('products/'+id)
|
21
|
+
def self.find (id, apiKey=nil)
|
22
|
+
responseXML = Recharge::Base.get('products/'+id, apiKey)
|
23
23
|
parse(responseXML.to_s)
|
24
24
|
end
|
25
|
-
def self.create (attributes = {})
|
26
|
-
responseXML = Recharge::Base.post('products', attributes)
|
25
|
+
def self.create (attributes = {}, apiKey=nil)
|
26
|
+
responseXML = Recharge::Base.post('products', attributes, apiKey)
|
27
27
|
parse(responseXML.to_s)
|
28
28
|
end
|
29
|
-
def update (attributes = {})
|
30
|
-
responseXML = Recharge::Base.post('products/'+self.id, attributes)
|
29
|
+
def update (attributes = {}, apiKey=nil)
|
30
|
+
responseXML = Recharge::Base.post('products/'+self.id, attributes, apiKey)
|
31
31
|
Product.parse(responseXML.to_s)
|
32
32
|
end
|
33
|
-
def destroy (
|
34
|
-
responseXML = Recharge::Base.delete('products/'+self.id)
|
33
|
+
def destroy (apiKey=nil)
|
34
|
+
responseXML = Recharge::Base.delete('products/'+self.id, apiKey)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
data/lib/recharge/transaction.rb
CHANGED
@@ -15,16 +15,16 @@ module Recharge
|
|
15
15
|
element :batchAmount, String
|
16
16
|
element :approvalCode, String
|
17
17
|
|
18
|
-
def self.purchase (attributes = {})
|
19
|
-
responseXML = Recharge::Base.post('purchase', attributes)
|
18
|
+
def self.purchase (attributes = {}, apiKey=nil)
|
19
|
+
responseXML = Recharge::Base.post('purchase', attributes, apiKey)
|
20
20
|
parse(responseXML.to_s)
|
21
21
|
end
|
22
|
-
def self.refund (attributes = {})
|
23
|
-
responseXML = Recharge::Base.post('return', attributes)
|
22
|
+
def self.refund (attributes = {}, apiKey=nil)
|
23
|
+
responseXML = Recharge::Base.post('return', attributes, apiKey)
|
24
24
|
parse(responseXML.to_s)
|
25
25
|
end
|
26
|
-
def self.void (attributes = {})
|
27
|
-
responseXML = Recharge::Base.post('void', attributes)
|
26
|
+
def self.void (attributes = {}, apiKey=nil)
|
27
|
+
responseXML = Recharge::Base.post('void', attributes, apiKey)
|
28
28
|
parse(responseXML.to_s)
|
29
29
|
end
|
30
30
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Recharge
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 4
|
10
|
+
version: 1.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Recharge
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-02-
|
18
|
+
date: 2012-02-17 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: happymapper
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- examples/customer.rb
|
56
56
|
- examples/paymethod.rb
|
57
57
|
- examples/product.rb
|
58
|
+
- examples/test.rb
|
58
59
|
- examples/transaction.rb
|
59
60
|
homepage: http://rechargebilling.com/api
|
60
61
|
licenses: []
|