wepay-rails 0.1.23 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.23
1
+ 0.1.24
@@ -15,17 +15,98 @@ module WepayRails
15
15
  "#{k.to_s}=#{v}"
16
16
  end.join('&')
17
17
 
18
- auth_base_uri = Rails.env.production? ? "https://api.wepay.com" : "https://stage.wepay.com"
18
+ "#{@base_uri}/v2/oauth2/authorize?#{query}"
19
+ end
20
+
21
+ def token_url(redirect_uri)
22
+ params = config_params(redirect_uri)
23
+
24
+ query = params.map do |k, v|
25
+ "#{k.to_s}=#{v}"
26
+ end.join('&')
27
+
28
+ "#{@base_uri}/v2/oauth2/authorize?#{query}"
29
+ end
19
30
 
20
- "#{auth_base_uri}/v2/oauth2/authorize?#{query}"
31
+ def config_params(redirect_uri)
32
+ {
33
+ :client_id => @config[:client_id],
34
+ :redirect_uri => redirect_uri,
35
+ :client_secret => @config[:client_secret],
36
+
37
+ }
21
38
  end
22
39
 
23
40
  def redirect_to_wepay_for_auth(redirect_uri, scope)
24
41
  redirect_to gateway.auth_code_url(redirect_uri, scope)
25
42
  end
26
43
 
44
+ def redirect_to_wepay_for_token(redirect_uri)
45
+ redirect_to gateway.token_url(redirect_uri)
46
+ end
47
+
27
48
  def gateway
28
- @gateway ||= WepayRails::Payments::Gateway.new
49
+ @gateway ||= Gateway.new
50
+ end
51
+
52
+ # Auth code is the code that we store in the model
53
+ def wepay_auth_code=(auth_code)
54
+ @wepay_auth_code = auth_code
55
+ end
56
+
57
+ # Auth code is the code that we store in the model
58
+ def wepay_auth_code
59
+ @wepay_auth_code
60
+ end
61
+
62
+ def wepay_auth_header
63
+ {'Authorization' => "Bearer: #{wepay_auth_code}"}
64
+ end
65
+
66
+ def wepay_user
67
+ response = self.class.get("/v2/user", {:headers => wepay_auth_header})
68
+ JSON.parse(response)
69
+ end
70
+
71
+ # From https://stage.wepay.com/developer/tutorial/authorization
72
+ # Request
73
+ # https://stage.wepay.com/v2/oauth2/token
74
+ # ?client_id=[your client id]
75
+ # &redirect_uri=[your redirect uri ex. 'http://exampleapp.com/wepay']
76
+ # &client_secret=[your client secret]
77
+ # &code=[the code you got in step one]
78
+ #
79
+ # Response
80
+ # {"user_id":"123456","access_token":"1337h4x0rzabcd12345","token_type":"BEARER"} Example
81
+ def initialize_wepay_access_token(auth_code)
82
+ response = gateway.get("/v2/oauth2/token", config_params("http://www.example.com").merge(:code => auth_code))
83
+ raise unless response.present?
84
+ json = JSON.parse(response.body)
85
+ wepay_access_token = json["access_token"]
86
+ raise unless wepay_access_token.present?
87
+ end
88
+
89
+ # Since we are saving the access token in the session,
90
+ # ensure key uniqueness. Might be a good idea to have this
91
+ # be a setting in the wepay.yml file.
92
+ def unique_wepay_access_token_key
93
+ :IODDR8856UUFG6788
94
+ end
95
+
96
+ # Access token is the OAUTH access token that is used for future
97
+ # comunique
98
+ def wepay_access_token=(value)
99
+ session[unique_wepay_access_token_key] = value
100
+ end
101
+
102
+ # Access token is the OAUTH access token that is used for future
103
+ # comunique
104
+ def wepay_access_token
105
+ session[unique_wepay_access_token_key]
106
+ end
107
+
108
+ def wepay_access_token_exists?
109
+ @access_token_exists ||= wepay_access_token.present?
29
110
  end
30
111
  end
31
112
  end
@@ -19,6 +19,10 @@ module WepayRails
19
19
  define_method "has_#{@column}?" do
20
20
  "#{@column}.present?"
21
21
  end
22
+
23
+ define_method "save_#{@column}" do |value|
24
+ "self.update_attribute(#{@column}, #{value})"
25
+ end
22
26
  end
23
27
 
24
28
 
data/lib/wepay-rails.rb CHANGED
@@ -4,23 +4,13 @@ module WepayRails
4
4
  require 'helpers/controller_helpers'
5
5
  class Gateway
6
6
  include HTTParty
7
- base_uri Rails.env.production? ? "https://wepayapi.com/v2" : "https://stage.wepayapi.com/v2"
8
7
 
9
- attr_accessor :wepay_auth_code
8
+ base_uri @base_uri
10
9
 
11
10
  def initialize(*args)
12
11
  yml = Rails.root.join('config', 'wepay.yml').to_s
13
12
  @config = YAML.load_file(yml)[Rails.env].symbolize_keys
14
- end
15
-
16
- def wepay_auth_header
17
- {'Authorization' => "Bearer: #{@wepay_auth_code}"}
18
- end
19
-
20
- def wepay_user
21
- File.open('/tmp/wepay.log', 'a') {|f| f.write("Wepay_user: #{wepay_auth_header.inspect}") }
22
- response = self.class.get("user", {:headers => wepay_auth_header})
23
- JSON.parse(response.body)
13
+ @base_uri = Rails.env.production? ? "https://api.wepay.com" : "https://stage.wepay.com"
24
14
  end
25
15
  end
26
16
 
data/wepay-rails.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wepay-rails}
8
- s.version = "0.1.23"
8
+ s.version = "0.1.24"
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"]
12
- s.date = %q{2011-07-17}
12
+ s.date = %q{2011-07-20}
13
13
  s.description = %q{Rails gem that interfaces with the WePay API}
14
14
  s.email = %q{adammede@gmail.com}
15
15
  s.extra_rdoc_files = [
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.1.23
4
+ version: 0.1.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-17 00:00:00.000000000 -07:00
12
+ date: 2011-07-20 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- requirement: &2151872000 !ruby/object:Gem::Requirement
17
+ requirement: &2151871780 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2151872000
25
+ version_requirements: *2151871780
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: shoulda
28
- requirement: &2151869360 !ruby/object:Gem::Requirement
28
+ requirement: &2151869320 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2151869360
36
+ version_requirements: *2151869320
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &2151866700 !ruby/object:Gem::Requirement
39
+ requirement: &2151866840 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2151866700
47
+ version_requirements: *2151866840
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: jeweler
50
- requirement: &2151865080 !ruby/object:Gem::Requirement
50
+ requirement: &2151865160 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.6.4
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2151865080
58
+ version_requirements: *2151865160
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rcov
61
- requirement: &2151863620 !ruby/object:Gem::Requirement
61
+ requirement: &2151863980 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,7 +66,7 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2151863620
69
+ version_requirements: *2151863980
70
70
  description: Rails gem that interfaces with the WePay API
71
71
  email: adammede@gmail.com
72
72
  executables: []
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: 4232558844581746746
109
+ hash: 3096857720111373096
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements: