blupee 0.1.0 → 0.1.1
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 +2 -1
- data/lib/blupee/api/ether.rb +54 -0
- data/lib/blupee/auth.rb +4 -2
- data/lib/blupee/errors.rb +100 -0
- data/lib/blupee/version.rb +1 -1
- metadata +4 -3
- data/lib/blupee/ether.rb +0 -55
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 052a22c88b4cfe6a9e334950ede54f3e8dfba972
|
4
|
+
data.tar.gz: bf1a87f3243fcc48e9500ab0ac66f0075999f9ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab33f2ed4a2e6c073d4366d1f65257c3da649244ceaaef27c59c77ffd98f006e2e0bbf583884003af3a26942bc0876133eebbe155b53df666d3563bd332e8f06
|
7
|
+
data.tar.gz: 71c780862d5eb6286c8d90c3ed721adc54ddd54aa6bd670995fbfa6badc27f9967040b18e1bc4a3d2818cbb6d17968849c1c0608154a8f8ffa82d9d4982c6442
|
data/lib/blupee.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require_relative "blupee/version"
|
2
|
-
require_relative
|
2
|
+
require_relative 'blupee/errors'
|
3
3
|
require_relative "blupee/auth"
|
4
4
|
require_relative "blupee/configuration"
|
5
5
|
require_relative "blupee/http_service"
|
6
6
|
require_relative "blupee/http_service/request"
|
7
7
|
require_relative "blupee/http_service/response"
|
8
|
+
require_relative "blupee/api/ether"
|
8
9
|
|
9
10
|
module Blupee
|
10
11
|
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Blupee
|
5
|
+
module API
|
6
|
+
class Ether
|
7
|
+
attr_reader :coin_symbol, :balance, :wallet, :transaction_hash
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
@coin_symbol = attributes["coin_symbol"]
|
11
|
+
@balance = attributes["balance"]
|
12
|
+
@wallet_address = attributes["wallet_address"]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.balance(id, options = {})
|
16
|
+
response = Blupee.make_request("/eth/#{id}", {}, "get", {:use_ssl => true}.merge!(options))
|
17
|
+
raise ServerError.new(response.status, response.body) if response.status >= 500
|
18
|
+
raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
19
|
+
response
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def self.new_wallet(args, options = {})
|
24
|
+
response = Blupee.make_request("/eth/new",
|
25
|
+
{}.merge!(args),
|
26
|
+
"post",
|
27
|
+
{:use_ssl => true,
|
28
|
+
format: :json}.merge!(options))
|
29
|
+
raise ServerError.new(response.status, response.body) if response.status >= 500
|
30
|
+
raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
31
|
+
response
|
32
|
+
end
|
33
|
+
|
34
|
+
# {:to_address=>"", :from_address=>"", :password=>"", :quantity=>0.001}
|
35
|
+
def self.send_ether(args, options = {})
|
36
|
+
response = Blupee.make_request("/eth/send",
|
37
|
+
{}.merge!(args),
|
38
|
+
"post",
|
39
|
+
{:use_ssl => true,
|
40
|
+
format: :json}.merge!(options))
|
41
|
+
|
42
|
+
raise ServerError.new(response.status, response.body) if response.status >= 500
|
43
|
+
raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
44
|
+
response
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def self.all
|
49
|
+
eth_wallet = JSON.parse(response.body)
|
50
|
+
eth_wallet.map { |attributes| new(attributes) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/blupee/auth.rb
CHANGED
@@ -65,13 +65,15 @@ module Blupee
|
|
65
65
|
|
66
66
|
|
67
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
|
68
70
|
response = Blupee.make_request("/#{endpoint}", {
|
69
71
|
:client_id => @client_id,
|
70
72
|
:client_secret => @client_secret
|
71
73
|
}.merge!(args), post ? "post" : "get", {:use_ssl => true, format: :json}.merge!(options))
|
72
74
|
|
73
|
-
|
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
|
75
77
|
|
76
78
|
response.body
|
77
79
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Blupee
|
2
|
+
|
3
|
+
class BlupeeError < StandardError; end
|
4
|
+
|
5
|
+
module API
|
6
|
+
|
7
|
+
# The OAuth signature is incomplete, invalid, or using an unsupported algorithm
|
8
|
+
class OAuthSignatureError < ::Blupee::BlupeeError; end
|
9
|
+
|
10
|
+
# Required for realtime updates validation
|
11
|
+
class AppSecretNotDefinedError < ::Blupee::BlupeeError; end
|
12
|
+
|
13
|
+
# Facebook responded with an error to an API request. If the exception contains a nil
|
14
|
+
# http_status, then the error was detected before making a call to Facebook. (e.g. missing access token)
|
15
|
+
class APIError < ::Blupee::BlupeeError
|
16
|
+
attr_accessor :http_status,
|
17
|
+
:response_body,
|
18
|
+
:error_type,
|
19
|
+
:error_code,
|
20
|
+
:error_subcode,
|
21
|
+
:error_message,
|
22
|
+
:error_user_msg,
|
23
|
+
:error_user_title,
|
24
|
+
:error_trace_id,
|
25
|
+
:error_debug,
|
26
|
+
:error_rev
|
27
|
+
|
28
|
+
# Create a new API Error
|
29
|
+
#
|
30
|
+
# @param http_status [Integer] The HTTP status code of the response
|
31
|
+
# @param response_body [String] The response body
|
32
|
+
# @param error_info One of the following:
|
33
|
+
# [Hash] The error information extracted from the request
|
34
|
+
# ("type", "code", "error_subcode", "message")
|
35
|
+
# [String] The error description
|
36
|
+
# If error_info is nil or not provided, the method will attempt to extract
|
37
|
+
# the error info from the response_body
|
38
|
+
#
|
39
|
+
# @return the newly created APIError
|
40
|
+
def initialize(http_status, response_body, error_info = nil)
|
41
|
+
if response_body
|
42
|
+
self.response_body = response_body.strip
|
43
|
+
else
|
44
|
+
self.response_body = ''
|
45
|
+
end
|
46
|
+
self.http_status = http_status
|
47
|
+
|
48
|
+
if error_info && error_info.is_a?(String)
|
49
|
+
message = error_info
|
50
|
+
else
|
51
|
+
unless error_info
|
52
|
+
begin
|
53
|
+
error_info = JSON.parse(response_body)['error'] if response_body
|
54
|
+
rescue
|
55
|
+
end
|
56
|
+
error_info ||= {}
|
57
|
+
end
|
58
|
+
|
59
|
+
self.error_type = error_info["type"]
|
60
|
+
self.error_message = error_info["message"]
|
61
|
+
|
62
|
+
self.error_trace_id = error_info["x-blu-trace-id"]
|
63
|
+
self.error_debug = error_info["x-blu-debug"]
|
64
|
+
self.error_rev = error_info["x-blu-rev"]
|
65
|
+
|
66
|
+
error_array = []
|
67
|
+
%w(type code error_subcode message error_user_title error_user_msg x-blu-trace-id).each do |key|
|
68
|
+
error_array << "#{key}: #{error_info[key]}" if error_info[key]
|
69
|
+
end
|
70
|
+
|
71
|
+
if error_array.empty?
|
72
|
+
message = self.response_body
|
73
|
+
else
|
74
|
+
message = error_array.join(', ')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
message += " [HTTP #{http_status}]" if http_status
|
78
|
+
|
79
|
+
super(message)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Facebook returned an invalid response body
|
84
|
+
class BadBlupeeAPIResponse < APIError; end
|
85
|
+
|
86
|
+
# Facebook responded with an error while attempting to request an access token
|
87
|
+
class OAuthTokenRequestError < APIError; end
|
88
|
+
|
89
|
+
# Any error with a 5xx HTTP status code
|
90
|
+
class ServerError < APIError; end
|
91
|
+
|
92
|
+
# Any error with a 4xx HTTP status code
|
93
|
+
class ClientError < APIError; end
|
94
|
+
|
95
|
+
# All graph API authentication failures.
|
96
|
+
class AuthenticationError < ClientError; end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
data/lib/blupee/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blupee Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,9 +166,10 @@ extensions: []
|
|
166
166
|
extra_rdoc_files: []
|
167
167
|
files:
|
168
168
|
- lib/blupee.rb
|
169
|
+
- lib/blupee/api/ether.rb
|
169
170
|
- lib/blupee/auth.rb
|
170
171
|
- lib/blupee/configuration.rb
|
171
|
-
- lib/blupee/
|
172
|
+
- lib/blupee/errors.rb
|
172
173
|
- lib/blupee/http_service.rb
|
173
174
|
- lib/blupee/http_service/request.rb
|
174
175
|
- lib/blupee/http_service/response.rb
|
data/lib/blupee/ether.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
module Blupee
|
5
|
-
class Ether
|
6
|
-
attr_reader :coin_symbol, :balance, :wallet, :transaction_hash
|
7
|
-
|
8
|
-
def initialize(attributes)
|
9
|
-
@coin_symbol = attributes["coin_symbol"]
|
10
|
-
@balance = attributes["balance"]
|
11
|
-
@wallet_address = attributes["wallet_address"]
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.balance(id, options = {})
|
15
|
-
response = Blupee.make_request("/eth/#{id}", {}, "get", {:use_ssl => true}.merge!(options))
|
16
|
-
# raise ServerError.new(response.status, response.body) if response.status >= 500
|
17
|
-
# raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
18
|
-
attributes = JSON.parse(response.body)
|
19
|
-
new(attributes)
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
def self.new_wallet(password, options = {})
|
24
|
-
response = Blupee.make_request("/eth/new", {
|
25
|
-
:password => password
|
26
|
-
}, "post", {:use_ssl => true, format: :json}.merge!(options))
|
27
|
-
|
28
|
-
# raise ServerError.new(response.status, response.body) if response.status >= 500
|
29
|
-
# raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
30
|
-
attributes = JSON.parse(response.body)
|
31
|
-
new(attributes)
|
32
|
-
end
|
33
|
-
|
34
|
-
# {:to_address=>"", :from_address=>"", :password=>"", :quantity=>0.001}
|
35
|
-
def self.send_ether(args, options = {})
|
36
|
-
response = Blupee.make_request("/eth/send",
|
37
|
-
{}.merge!(args),
|
38
|
-
"post",
|
39
|
-
{:use_ssl => true,
|
40
|
-
format: :json}.merge!(options))
|
41
|
-
|
42
|
-
# raise ServerError.new(response.status, response.body) if response.status >= 500
|
43
|
-
# raise OAuthTokenRequestError.new(response.status, response.body) if response.status >= 400
|
44
|
-
puts response.body
|
45
|
-
attributes = JSON.parse(response.body)
|
46
|
-
new(attributes)
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
def self.all
|
51
|
-
eth_wallet = JSON.parse(response.body)
|
52
|
-
eth_wallet.map { |attributes| new(attributes) }
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|