blupee 0.1.5 → 0.1.6
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.
- checksums.yaml +4 -4
- data/lib/blupee.rb +1 -1
- data/lib/blupee/api/auth.rb +84 -0
- data/lib/blupee/version.rb +1 -1
- metadata +2 -2
- data/lib/blupee/auth.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5921164f572dc621003e32b49ab572369e3fa604
|
4
|
+
data.tar.gz: 93741fa54d469bd49232c5dfaf3b855a5dbeb861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e5801dbb75eece2669ce4aa61fcf14d18d5feadb28638c365ad2c00b5c2328330488eb11bfe24bd6080b6d38505ff6a6b4bb14986f199ce009b9d8beede818d
|
7
|
+
data.tar.gz: e39bbdb8fe609360f6a523fe8f82f5adb9639c814bf33c1031e1caf84529d8d58ed8a40647b95c9df55bcd4236e49ea1f7f25ada645c1d923f218c596c882034
|
data/lib/blupee.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
require_relative "blupee/version"
|
2
2
|
require_relative 'blupee/errors'
|
3
|
-
require_relative "blupee/auth"
|
4
3
|
require_relative "blupee/configuration"
|
5
4
|
require_relative "blupee/http_service"
|
6
5
|
require_relative "blupee/http_service/request"
|
7
6
|
require_relative "blupee/http_service/response"
|
7
|
+
require_relative "blupee/api/auth"
|
8
8
|
require_relative "blupee/api/ether"
|
9
9
|
require_relative "blupee/api/omise_go"
|
10
10
|
require_relative "blupee/api/token"
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# OpenSSL and Base64 are required to support signed_request
|
2
|
+
require 'openssl'
|
3
|
+
require 'base64'
|
4
|
+
|
5
|
+
module Blupee
|
6
|
+
module API
|
7
|
+
class Auth
|
8
|
+
attr_reader :client_id, :client_secret
|
9
|
+
|
10
|
+
# Creates a new client.
|
11
|
+
#
|
12
|
+
# @param client_id [String, Integer] a Blupee client ID
|
13
|
+
# @param client_secret a Blupee client secret
|
14
|
+
def initialize(client_id = nil, client_secret = nil)
|
15
|
+
@client_id = client_id || Blupee.config.client_id
|
16
|
+
@client_secret = client_secret || Blupee.config.client_secret
|
17
|
+
end
|
18
|
+
|
19
|
+
# access tokens
|
20
|
+
|
21
|
+
# Fetches an access token, token expiration, and other info from Blupee.
|
22
|
+
# Useful when you've received an OAuth code using the server-side authentication process.
|
23
|
+
# @see url_for_oauth_code
|
24
|
+
#
|
25
|
+
# @note (see #url_for_oauth_code)
|
26
|
+
#
|
27
|
+
# @param code (see #url_for_access_token)
|
28
|
+
# @param options any additional parameters to send to Blupee when redeeming the token
|
29
|
+
#
|
30
|
+
# @raise Blupee::OAuthTokenRequestError if Blupee returns an error response
|
31
|
+
#
|
32
|
+
# @return a hash of the access token info returned by Blupee (token, expiration, etc.)
|
33
|
+
def get_access_token_info(options = {})
|
34
|
+
# convenience method to get a the application's sessionless access token
|
35
|
+
get_token_from_server({}, true, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Fetches the application's access token (ignoring expiration and other info).
|
39
|
+
# @see get_app_access_token_info
|
40
|
+
#
|
41
|
+
# @param (see #get_app_access_token_info)
|
42
|
+
#
|
43
|
+
# @return the application access token
|
44
|
+
def get_access_token(options = {})
|
45
|
+
if info = get_access_token_info(options)
|
46
|
+
Blupee.config.access_token = info["access_token"]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
protected
|
51
|
+
|
52
|
+
def get_token_from_server(args, post = false, options = {})
|
53
|
+
# fetch the result from Blupee's servers
|
54
|
+
response = fetch_token_string(args, post, "auth", options)
|
55
|
+
parse_access_token(response)
|
56
|
+
end
|
57
|
+
|
58
|
+
def parse_access_token(response_text)
|
59
|
+
JSON.parse(response_text)
|
60
|
+
rescue JSON::ParserError
|
61
|
+
response_text.split("&").inject({}) do |hash, bit|
|
62
|
+
key, value = bit.split("=")
|
63
|
+
hash.merge!(key => value)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def fetch_token_string(args, post = false, endpoint = "auth", options = {})
|
69
|
+
raise ClientError if @client_id == nil
|
70
|
+
raise ClientError if @client_secret == nil
|
71
|
+
response = Blupee.make_request("/#{endpoint}", {
|
72
|
+
:client_id => @client_id,
|
73
|
+
:client_secret => @client_secret
|
74
|
+
}.merge!(args), post ? "post" : "get", {:use_ssl => true, format: :json}.merge!(options))
|
75
|
+
|
76
|
+
raise ServerError.new(response.status, response.body) if response.status >= 500
|
77
|
+
raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
78
|
+
|
79
|
+
response.body
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/lib/blupee/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blupee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blupee Inc.
|
@@ -173,8 +173,8 @@ files:
|
|
173
173
|
- lib/blupee/api/omise_go.rb
|
174
174
|
- lib/blupee/api/token.rb
|
175
175
|
- lib/blupee/api/ether.rb
|
176
|
+
- lib/blupee/api/auth.rb
|
176
177
|
- lib/blupee/version.rb
|
177
|
-
- lib/blupee/auth.rb
|
178
178
|
- lib/blupee/configuration.rb
|
179
179
|
homepage: https://github.com/fogonthedowns/blupee_ruby
|
180
180
|
licenses:
|
data/lib/blupee/auth.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
# OpenSSL and Base64 are required to support signed_request
|
2
|
-
require 'openssl'
|
3
|
-
require 'base64'
|
4
|
-
|
5
|
-
module Blupee
|
6
|
-
class Auth
|
7
|
-
attr_reader :client_id, :client_secret
|
8
|
-
|
9
|
-
# Creates a new client.
|
10
|
-
#
|
11
|
-
# @param client_id [String, Integer] a Blupee client ID
|
12
|
-
# @param client_secret a Blupee client secret
|
13
|
-
def initialize(client_id = nil, client_secret = nil)
|
14
|
-
@client_id = client_id || Blupee.config.client_id
|
15
|
-
@client_secret = client_secret || Blupee.config.client_secret
|
16
|
-
end
|
17
|
-
|
18
|
-
# access tokens
|
19
|
-
|
20
|
-
# Fetches an access token, token expiration, and other info from Blupee.
|
21
|
-
# Useful when you've received an OAuth code using the server-side authentication process.
|
22
|
-
# @see url_for_oauth_code
|
23
|
-
#
|
24
|
-
# @note (see #url_for_oauth_code)
|
25
|
-
#
|
26
|
-
# @param code (see #url_for_access_token)
|
27
|
-
# @param options any additional parameters to send to Blupee when redeeming the token
|
28
|
-
#
|
29
|
-
# @raise Blupee::OAuthTokenRequestError if Blupee returns an error response
|
30
|
-
#
|
31
|
-
# @return a hash of the access token info returned by Blupee (token, expiration, etc.)
|
32
|
-
def get_access_token_info(options = {})
|
33
|
-
# convenience method to get a the application's sessionless access token
|
34
|
-
get_token_from_server({}, true, options)
|
35
|
-
end
|
36
|
-
|
37
|
-
# Fetches the application's access token (ignoring expiration and other info).
|
38
|
-
# @see get_app_access_token_info
|
39
|
-
#
|
40
|
-
# @param (see #get_app_access_token_info)
|
41
|
-
#
|
42
|
-
# @return the application access token
|
43
|
-
def get_access_token(options = {})
|
44
|
-
if info = get_access_token_info(options)
|
45
|
-
Blupee.config.access_token = info["access_token"]
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
protected
|
50
|
-
|
51
|
-
def get_token_from_server(args, post = false, options = {})
|
52
|
-
# fetch the result from Blupee's servers
|
53
|
-
response = fetch_token_string(args, post, "auth", options)
|
54
|
-
parse_access_token(response)
|
55
|
-
end
|
56
|
-
|
57
|
-
def parse_access_token(response_text)
|
58
|
-
JSON.parse(response_text)
|
59
|
-
rescue JSON::ParserError
|
60
|
-
response_text.split("&").inject({}) do |hash, bit|
|
61
|
-
key, value = bit.split("=")
|
62
|
-
hash.merge!(key => value)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
|
67
|
-
def fetch_token_string(args, post = false, endpoint = "auth", options = {})
|
68
|
-
raise ClientError if @client_id == nil
|
69
|
-
raise ClientError if @client_secret == nil
|
70
|
-
response = Blupee.make_request("/#{endpoint}", {
|
71
|
-
:client_id => @client_id,
|
72
|
-
:client_secret => @client_secret
|
73
|
-
}.merge!(args), post ? "post" : "get", {:use_ssl => true, format: :json}.merge!(options))
|
74
|
-
|
75
|
-
raise ServerError.new(response.status, response.body) if response.status >= 500
|
76
|
-
raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
77
|
-
|
78
|
-
response.body
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|