wepay-rails 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,5 +1,3 @@
1
- = IMPORTANT - This gem is under heavy development and is in extreme alpha phase. As soon as it's in a release state (very soon), I will update the MAJOR version to 1. If you are interested in helping, please drop me a message.
2
-
3
1
  = wepay-rails
4
2
 
5
3
  Wepay-Rails allows your rails app to accept payments with Wepay (http://www.wepay.com).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 1.0.0
@@ -2,33 +2,27 @@ module WepayRails
2
2
  module Api
3
3
  module AccountMethods
4
4
  def create_account(params)
5
- response = self.class.post("#{@base_uri}/account/create", {:headers => wepay_auth_header}.merge!(:body => params))
6
- JSON.parse(response.body)
5
+ self.call("/account/create", {:body => params})
7
6
  end
8
7
 
9
8
  def get_account(account_id)
10
- response = self.class.post("#{@base_uri}/account", {:headers => wepay_auth_header}.merge!(:body => {:account_id => account_id}))
11
- JSON.parse(response.body)
9
+ self.call("/account", {:body => {:account_id => account_id}})
12
10
  end
13
11
 
14
12
  def find_account(args)
15
- response = self.class.post("#{@base_uri}/account/find", {:headers => wepay_auth_header}.merge!(:body => args))
16
- JSON.parse(response.body)
13
+ self.call("/account/find", {:body => args})
17
14
  end
18
15
 
19
- def modify_account(params)
20
- response = self.class.put("#{@base_uri}/account/modify", {:headers => wepay_auth_header}.merge!(:body => args))
21
- JSON.parse(response.body)
16
+ def modify_account(args)
17
+ self.call("/account/modify", {:body => args})
22
18
  end
23
19
 
24
20
  def delete_account(account_id)
25
- response = self.class.post("#{@base_uri}/account/delete", {:headers => wepay_auth_header}.merge!(:body => {:account_id => account_id}))
26
- JSON.parse(response.body)
21
+ self.call("/account/delete", {:body => {:account_id => account_id}})
27
22
  end
28
23
 
29
24
  def get_account_balance(account_id)
30
- response = self.class.post("#{@base_uri}/account/balance", {:headers => wepay_auth_header}.merge!(:body => {:account_id => account_id}))
31
- JSON.parse(response.body)
25
+ self.call("/account/balance", {:body => {:account_id => account_id}})
32
26
  end
33
27
  end
34
28
  end
@@ -50,13 +50,11 @@ module WepayRails
50
50
  :account_id => @wepay_config[:account_id]
51
51
  }.merge(parms)
52
52
 
53
- response = self.class.post("#{@base_uri}/checkout/create", {:headers => wepay_auth_header}.merge!(:body => defaults))
54
- JSON.parse(response.body)
53
+ self.call("/checkout/create", {:body => defaults})
55
54
  end
56
55
 
57
56
  def lookup_checkout(checkout_id)
58
- response = self.class.post("#{@base_uri}/checkout", {:headers => wepay_auth_header}.merge!(:body => {:checkout_id => checkout_id}))
59
- JSON.parse(response.body)
57
+ self.call("/checkout", {:body => {:checkout_id => checkout_id}})
60
58
  end
61
59
  end
62
60
  end
data/lib/wepay-rails.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'active_record'
2
- require 'helpers/model_helpers'
3
2
  require 'helpers/controller_helpers'
4
3
  require 'api/account_methods'
5
4
  require 'api/checkout_methods'
@@ -92,31 +91,30 @@ module WepayRails
92
91
  :code => auth_code
93
92
  }
94
93
 
95
- response = self.class.post("#{@base_uri}/oauth2/token", :body => params)
96
- json = JSON.parse(response.body)
94
+ response = self.call("/oauth2/token", {:body => params})
97
95
 
98
- if json.has_key?("error")
99
- if json.has_key?("error_description")
100
- if ['invalid code parameter','the code has expired'].include?(json['error_description'])
101
- raise WepayRails::Exceptions::ExpiredTokenError.new("Token either expired or invalid: #{json["error_description"]}")
96
+ if response.has_key?("error")
97
+ if response.has_key?("error_description")
98
+ if ['invalid code parameter','the code has expired'].include?(response['error_description'])
99
+ raise WepayRails::Exceptions::ExpiredTokenError.new("Token either expired or invalid: #{response["error_description"]}")
102
100
  end
103
- raise WepayRails::Exceptions::AccessTokenError.new(json["error_description"])
101
+ raise WepayRails::Exceptions::AccessTokenError.new(response["error_description"])
104
102
  end
105
103
  end
106
104
 
107
- raise WepayRails::Exceptions::AccessTokenError.new("A problem occurred trying to get the access token: #{json.inspect}") unless json.has_key?("access_token")
105
+ raise WepayRails::Exceptions::AccessTokenError.new("A problem occurred trying to get the access token: #{response.inspect}") unless response.has_key?("access_token")
108
106
 
109
107
  @wepay_auth_code = auth_code
110
- @wepay_access_token = json["access_token"]
108
+ @wepay_access_token = response["access_token"]
111
109
  end
112
110
 
113
111
  # Get the auth code url that will be used to fetch the auth code for the customer
114
112
  # arguments are the redirect_uri and an array of permissions that your application needs
115
113
  # ex. ['manage_accounts','collect_payments','view_balance','view_user']
116
114
  def auth_code_url(params = {})
117
- params[:client_id] ||= @wepay_config[:client_id]
115
+ params[:client_id] ||= @wepay_config[:client_id]
118
116
  params[:redirect_uri] ||= @wepay_config[:redirect_uri]
119
- params[:scope] ||= WepayRails::Configuration.settings[:scope].join(',')
117
+ params[:scope] ||= WepayRails::Configuration.settings[:scope].join(',')
120
118
 
121
119
  query = params.map do |k, v|
122
120
  "#{k.to_s}=#{v}"
@@ -136,12 +134,12 @@ module WepayRails
136
134
  # per request. Any subsequent calls to wepay_user will return the data
137
135
  # retrieved from the first call.
138
136
  def wepay_user
139
- user_api = lambda {|headers|
140
- response = self.class.post("#{@base_uri}/user", {:headers => headers})
141
- JSON.parse(response.body)
142
- }
137
+ @wepay_user ||= self.call("/user")
138
+ end
143
139
 
144
- @wepay_user ||= user_api.call(wepay_auth_header)
140
+ def call(api_path, params={})
141
+ response = self.class.post("#{@base_uri}#{api_path}", {:headers => wepay_auth_header}.merge!(params))
142
+ JSON.parse(response.body)
145
143
  end
146
144
 
147
145
  include WepayRails::Api::CheckoutMethods
@@ -152,8 +150,4 @@ module WepayRails
152
150
  include WepayRails::Helpers::ControllerHelpers
153
151
  end
154
152
 
155
- def self.included(base)
156
- base.extend WepayRails::Helpers::ModelHelpers
157
- end
158
153
  end
159
- ActiveRecord::Base.send(:include, WepayRails)
data/wepay-rails.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "wepay-rails"
8
- s.version = "0.2.2"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Medeiros"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wepay-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-11-25 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &13677460 !ruby/object:Gem::Requirement
16
+ requirement: &21936620 !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: *13677460
24
+ version_requirements: *21936620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: shoulda
27
- requirement: &13676180 !ruby/object:Gem::Requirement
27
+ requirement: &21934320 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *13676180
35
+ version_requirements: *21934320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &13674860 !ruby/object:Gem::Requirement
38
+ requirement: &21932700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.0.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *13674860
46
+ version_requirements: *21932700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: jeweler
49
- requirement: &13652260 !ruby/object:Gem::Requirement
49
+ requirement: &21931200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.6.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *13652260
57
+ version_requirements: *21931200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rcov
60
- requirement: &13649680 !ruby/object:Gem::Requirement
60
+ requirement: &21929880 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *13649680
68
+ version_requirements: *21929880
69
69
  description: Rails gem that interfaces with the WePay API
70
70
  email: adammede@gmail.com
71
71
  executables: []
@@ -114,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  version: '0'
115
115
  segments:
116
116
  - 0
117
- hash: 1958917921115598228
117
+ hash: 454732368271274683
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  none: false
120
120
  requirements: