wepay-rails 0.1.28 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.28
1
+ 0.1.29
@@ -1,77 +1,19 @@
1
1
  module WepayRails
2
2
  module Helpers
3
3
  module ControllerHelpers
4
- # Get the auth code for the customer
5
- # arguments are the redirect_uri and an array of permissions that your application needs
6
- # ex. ['manage_accounts','collect_payments','view_balance','view_user']
7
- def auth_code_url(redirect_uri, permissions)
8
- params = {
9
- :client_id => @config[:client_id],
10
- :redirect_uri => redirect_uri,
11
- :scope => permissions.join(',')
12
- }
13
4
 
14
- query = params.map do |k, v|
15
- "#{k.to_s}=#{v}"
16
- end.join('&')
17
-
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
30
-
31
- def config_params(redirect_uri)
32
- {
33
- :client_id => wepay_config[:client_id],
34
- :redirect_uri => redirect_uri,
35
- :client_secret => wepay_config[:client_secret],
36
-
37
- }
38
- end
39
-
40
- def wepay_config
41
- gateway.config
5
+ def redirect_to_wepay_for_auth(scope)
6
+ redirect_to gateway.auth_code_url(scope)
42
7
  end
43
8
 
44
- def redirect_to_wepay_for_auth(redirect_uri, scope)
45
- redirect_to gateway.auth_code_url(redirect_uri, scope)
46
- end
47
-
48
- def redirect_to_wepay_for_token(redirect_uri)
49
- redirect_to gateway.token_url(redirect_uri)
9
+ def redirect_to_wepay_for_token
10
+ redirect_to gateway.token_url
50
11
  end
51
12
 
52
13
  def gateway
53
14
  @gateway ||= WepayRails::Payments::Gateway.new
54
15
  end
55
16
 
56
- # Auth code is the code that we store in the model
57
- def wepay_auth_code=(auth_code)
58
- @wepay_auth_code = auth_code
59
- end
60
-
61
- # Auth code is the code that we store in the model
62
- def wepay_auth_code
63
- @wepay_auth_code
64
- end
65
-
66
- def wepay_auth_header
67
- {'Authorization' => "Bearer: #{wepay_auth_code}"}
68
- end
69
-
70
- def wepay_user
71
- response = self.class.get("/v2/user", {:headers => wepay_auth_header})
72
- JSON.parse(response)
73
- end
74
-
75
17
  # From https://stage.wepay.com/developer/tutorial/authorization
76
18
  # Request
77
19
  # https://stage.wepay.com/v2/oauth2/token
@@ -83,22 +25,7 @@ module WepayRails
83
25
  # Response
84
26
  # {"user_id":"123456","access_token":"1337h4x0rzabcd12345","token_type":"BEARER"} Example
85
27
  def initialize_wepay_access_token(auth_code)
86
- logger.debug "WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - receiving #{auth_code}"
87
- File.open('/tmp/fugaze.log','a') {|f| f.write("WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - receiving #{auth_code}")}
88
- response = gateway.get("/v2/oauth2/token", config_params("http://www.example.com").merge(:code => auth_code))
89
- logger.debug "WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - response #{response.inspect}"
90
- File.open('/tmp/fugaze.log','a') {|f| f.write("WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - response #{response.inspect}")}
91
- raise unless response.present?
92
- logger.debug "WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - response is present"
93
- File.open('/tmp/fugaze.log','a') {|f| f.write("WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - response is present")}
94
- logger.debug response.inspect
95
- File.open('/tmp/fugaze.log','a') {|f| f.write(response.inspect)}
96
- json = JSON.parse(response.body)
97
- logger.debug "WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - json is #{json.inspect}"
98
- File.open('/tmp/fugaze.log','a') {|f| f.write("WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - json is #{json.inspect}")}
99
- wepay_access_token = json["access_token"]
100
- logger.debug "WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - wepay_access_token is #{wepay_access_token.inspect}"
101
- File.open('/tmp/fugaze.log','a') {|f| f.write("WepayRails::Helpers::ControllerHelpers#initialize_wepay_access_token - after call to wepay - wepay_access_token is #{wepay_access_token.inspect}")}
28
+ wepay_access_token = gateway.access_token(auth_code)
102
29
  raise unless wepay_access_token.present?
103
30
  end
104
31
 
data/lib/wepay-rails.rb CHANGED
@@ -7,13 +7,52 @@ module WepayRails
7
7
 
8
8
  base_uri @base_uri
9
9
 
10
- attr_accessor :config
10
+ attr_accessor :wepay_access_token, :wepay_auth_code
11
11
 
12
12
  def initialize(*args)
13
13
  yml = Rails.root.join('config', 'wepay.yml').to_s
14
14
  @config = YAML.load_file(yml)[Rails.env].symbolize_keys
15
15
  @base_uri = Rails.env.production? ? "https://api.wepay.com" : "https://stage.wepay.com"
16
16
  end
17
+
18
+ def access_token(auth_code)
19
+ @wepay_auth_code = auth_code
20
+ response = self.get("/v2/oauth2/token", @config.merge(:code => auth_code))
21
+ json = JSON.parse(response.body)
22
+ File.open('/tmp/wepay-rails.log','a') {|f| f.write(response.body)}
23
+ File.open('/tmp/wepay-rails.log','a') {|f| f.write(json.inspect)}
24
+ @wepay_access_token = json["access_token"]
25
+ end
26
+
27
+ # Get the auth code for the customer
28
+ # arguments are the redirect_uri and an array of permissions that your application needs
29
+ # ex. ['manage_accounts','collect_payments','view_balance','view_user']
30
+ def auth_code_url(permissions)
31
+ params = @config.merge(:scope => permissions.join(','))
32
+
33
+ query = params.map do |k, v|
34
+ "#{k.to_s}=#{v}"
35
+ end.join('&')
36
+
37
+ "#{@base_uri}/v2/oauth2/authorize?#{query}"
38
+ end
39
+
40
+ def token_url
41
+ query = @config.map do |k, v|
42
+ "#{k.to_s}=#{v}"
43
+ end.join('&')
44
+
45
+ "#{@base_uri}/v2/oauth2/authorize?#{query}"
46
+ end
47
+
48
+ def wepay_auth_header
49
+ {'Authorization' => "Bearer: #{@wepay_access_token}"}
50
+ end
51
+
52
+ def wepay_user
53
+ response = self.class.get("/v2/user", {:headers => wepay_auth_header})
54
+ JSON.parse(response.body)
55
+ end
17
56
  end
18
57
 
19
58
  include WepayRails::Helpers::ControllerHelpers
data/wepay-rails.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{wepay-rails}
8
- s.version = "0.1.28"
8
+ s.version = "0.1.29"
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.1.28
4
+ version: 0.1.29
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- requirement: &2151870880 !ruby/object:Gem::Requirement
17
+ requirement: &2151870340 !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: *2151870880
25
+ version_requirements: *2151870340
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: shoulda
28
- requirement: &2151868200 !ruby/object:Gem::Requirement
28
+ requirement: &2151867800 !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: *2151868200
36
+ version_requirements: *2151867800
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &2151865640 !ruby/object:Gem::Requirement
39
+ requirement: &2151865600 !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: *2151865640
47
+ version_requirements: *2151865600
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: jeweler
50
- requirement: &2151864680 !ruby/object:Gem::Requirement
50
+ requirement: &2151864600 !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: *2151864680
58
+ version_requirements: *2151864600
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rcov
61
- requirement: &2151863360 !ruby/object:Gem::Requirement
61
+ requirement: &2151862900 !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: *2151863360
69
+ version_requirements: *2151862900
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: 1560374341972796065
109
+ hash: -622303022603351918
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements: