fbox 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE +23 -0
- data/README.md +90 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/fbox.gemspec +29 -0
- data/lib/fbox.rb +28 -0
- data/lib/fbox/client.rb +147 -0
- data/lib/fbox/http_client.rb +89 -0
- data/lib/fbox/version.rb +27 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4184e7461676c58b9407104858c03b406e1f4119
|
4
|
+
data.tar.gz: 84ffa0cdc8511c09bac127a47f9f5ddb37b4211d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14243ed18e6b3c75a373f91e2af39348829f20cc12a3cba6f48e373deb2705c98a09772b35dbab66d17ebe80e1ab3b44eb8a73f4428d23acbb8a93e983bad3eb
|
7
|
+
data.tar.gz: 5336158d4ecd3c9707d73b6ced228f34d9373bd48788310ad9fd2ed2b1fb9a2f186a2ad731d0dcc5a394a6cc62fb190dd2b0d7614dc32c82d3970fbdb6cb8b7a
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2015, Hothza
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# Fbox
|
2
|
+
|
3
|
+
This gem is a [FaucetBox](https://faucetbox.com) REST API helper. It allows you
|
4
|
+
to integrate FaucetBox API in an easy way in your RubyOnRails application.
|
5
|
+
|
6
|
+
Build status: [](https://travis-ci.org/Hothza/fbox)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'fbox'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install fbox
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Fbox has four FaucetBox API releated methods:
|
27
|
+
|
28
|
+
- currencies - returns a list of currently supported coin types by FaucetBox
|
29
|
+
```ruby
|
30
|
+
require 'pp'
|
31
|
+
require 'fbox'
|
32
|
+
|
33
|
+
api_key = '4VdBEIAQKPpZ4SWOhQLUMn7mMNVql' # FBox example API key
|
34
|
+
fbox = Fbox::Client.new({:api_key => api_key})
|
35
|
+
currencies = fbox.currencies()
|
36
|
+
|
37
|
+
pp "Supported currencies: #{currencies}\n"
|
38
|
+
```
|
39
|
+
|
40
|
+
- balance(currency) - returns current balance fo given currency, if not set then BTC is used as a default one
|
41
|
+
```ruby
|
42
|
+
require 'pp'
|
43
|
+
require 'fbox'
|
44
|
+
|
45
|
+
# Unfortunately at this moment API key used in examples on FaucetBox site
|
46
|
+
# gives 403 status, so you have tou use your own
|
47
|
+
|
48
|
+
api_key = '4VdBEIAQKPpZ4SWOhQLUMn7mMNVql' # Put your API key here
|
49
|
+
currency = 'BTC'
|
50
|
+
|
51
|
+
fbox = Fbox::Client.new({:api_key => api_key})
|
52
|
+
balance = fbox.balance()
|
53
|
+
pp "balance: #{balance}\n"
|
54
|
+
```
|
55
|
+
|
56
|
+
- payment(to, amount, referral = false, currency = '') - sends a given amount of coins
|
57
|
+
(in given currency, if not set than BTC is used as a default) from your faucet into destination address
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
require 'pp'
|
61
|
+
require 'fbox'
|
62
|
+
|
63
|
+
api_key = '' # Put here your API key
|
64
|
+
address = '' # Put here destination address (BTC, LTC, or other supported by FaucetBox)
|
65
|
+
amount = 10 # Amount of satoshis to send
|
66
|
+
referral = false # Is this a referral payment?
|
67
|
+
|
68
|
+
fbox = Fbox::Client.new({:api_key => api_key})
|
69
|
+
payment = fbox.payment(address, amount, referral)
|
70
|
+
pp "payment: #{payment}\n"
|
71
|
+
```
|
72
|
+
|
73
|
+
- payouts(count = 1, currency = '') - returns list of payouts (no more than 10)
|
74
|
+
from last 30 days for given currency (if not set than BTC is used as a default one)
|
75
|
+
*WARNING:* This API call gives timeouts - use with care (it is probably disabled on FaucetBox)
|
76
|
+
|
77
|
+
|
78
|
+
There are also two helper methods:
|
79
|
+
|
80
|
+
- is_response_ok?(body) - returns true if FaucetBox respone has status: 200
|
81
|
+
- is_address_valid?(address) - checks if given coin address is valid (proper length, correct checksum, etc.)
|
82
|
+
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
1. Fork it ( https://github.com/Hothza/fbox/fork )
|
87
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
88
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
89
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
90
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fbox"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/fbox.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fbox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fbox"
|
8
|
+
spec.version = Fbox::VERSION
|
9
|
+
spec.authors = ["Hothza"]
|
10
|
+
spec.email = ["hothza@users.noreply.github.com"]
|
11
|
+
|
12
|
+
# if spec.respond_to?(:metadata)
|
13
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com' to prevent pushes to rubygems.org, or delete to allow pushes to any server."
|
14
|
+
# end
|
15
|
+
|
16
|
+
spec.summary = %q{Fbox - FaucetBox REST API helper. It allows you to integrate FaucetBox API in an easy way in your RubyOnRails application. }
|
17
|
+
spec.homepage = "https://github.com/Hothza/fbox"
|
18
|
+
spec.license = "BSD"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
spec.add_dependency "minitest"
|
28
|
+
spec.add_dependency "coins_address_validator"
|
29
|
+
end
|
data/lib/fbox.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2015, Hothza
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
25
|
+
require "fbox/version"
|
26
|
+
require "fbox/client"
|
27
|
+
require "fbox/http_client"
|
28
|
+
|
data/lib/fbox/client.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# Copyright (c) 2015, Hothza
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
25
|
+
require 'json'
|
26
|
+
require 'openssl'
|
27
|
+
require 'coins_address_validator'
|
28
|
+
|
29
|
+
module Fbox
|
30
|
+
class Client
|
31
|
+
attr_reader :options
|
32
|
+
|
33
|
+
DEFAULT_OPTIONS = {
|
34
|
+
:site => 'https://faucetbox.com',
|
35
|
+
:context_path => '',
|
36
|
+
:rest_base_path => "/api/v1/",
|
37
|
+
:ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER,
|
38
|
+
:use_ssl => true,
|
39
|
+
:api_key => '',
|
40
|
+
}
|
41
|
+
|
42
|
+
FBOX_API = {
|
43
|
+
:balance => 'balance',
|
44
|
+
:currencies => 'currencies',
|
45
|
+
:payment => 'send',
|
46
|
+
:payouts => 'payouts',
|
47
|
+
}
|
48
|
+
|
49
|
+
@@addres_validator = nil
|
50
|
+
|
51
|
+
def initialize(options={})
|
52
|
+
@@addres_validator = CoinsAddressValidator::Validator.new
|
53
|
+
options = DEFAULT_OPTIONS.merge(options)
|
54
|
+
@options = options
|
55
|
+
@options[:rest_base_path] = @options[:context_path] + @options[:rest_base_path]
|
56
|
+
|
57
|
+
@request_client = HttpClient.new(@options)
|
58
|
+
|
59
|
+
@options.freeze
|
60
|
+
end
|
61
|
+
|
62
|
+
def balance(currency = '')
|
63
|
+
path = prepare_api_request(FBOX_API[:balance])
|
64
|
+
form_params = {
|
65
|
+
'api_key' => @options[:api_key],
|
66
|
+
'currency' => !currency.empty? ? currency : 'BTC'
|
67
|
+
}
|
68
|
+
response = request(path, form_params)
|
69
|
+
process_response(response)
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
## Use with care it gives timeouts, probably this API call is disabled on FaucetBox
|
74
|
+
##
|
75
|
+
def payouts(count = 1, currency = '')
|
76
|
+
if count.to_i > 0 && count <= 10
|
77
|
+
path = prepare_api_request(FBOX_API[:payouts])
|
78
|
+
form_params = {
|
79
|
+
'api_key' => @options[:api_key],
|
80
|
+
'count' => count,
|
81
|
+
'currency' => !currency.empty? ? currency : 'BTC'
|
82
|
+
}
|
83
|
+
response = request(path, form_params)
|
84
|
+
process_response(response)
|
85
|
+
else
|
86
|
+
invalid_parameter("'count' parameter has to be in 1..10 range")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def currencies()
|
91
|
+
path = prepare_api_request(FBOX_API[:currencies])
|
92
|
+
response = request(path)
|
93
|
+
process_response(response)
|
94
|
+
end
|
95
|
+
|
96
|
+
def payment(to, amount, referral = false, currency = '')
|
97
|
+
if !to.empty? && self.is_address_valid?(to) && amount > 0
|
98
|
+
path = prepare_api_request(FBOX_API[:payment])
|
99
|
+
form_params = {
|
100
|
+
'api_key' => @options[:api_key],
|
101
|
+
'to' => to,
|
102
|
+
'amount' => amount,
|
103
|
+
'currency' => !currency.empty? ? currency : 'BTC',
|
104
|
+
'referral' => referral.to_s
|
105
|
+
}
|
106
|
+
response = request(path, form_params)
|
107
|
+
process_response(response)
|
108
|
+
else
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def is_response_ok?(body)
|
114
|
+
body['status'].present? && body['status'] == 200
|
115
|
+
end
|
116
|
+
|
117
|
+
def is_address_valid?(address)
|
118
|
+
@@addres_validator.is_address_valid?(address)
|
119
|
+
end
|
120
|
+
|
121
|
+
private
|
122
|
+
def invalid_parameter(message)
|
123
|
+
{ :error => message }.to_json
|
124
|
+
end
|
125
|
+
|
126
|
+
def process_response(response)
|
127
|
+
if response.code == '200'
|
128
|
+
JSON.parse(response.body)
|
129
|
+
else
|
130
|
+
{ :status => response.code.to_i, :message => response.msg.to_s }.to_json
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def prepare_api_request(api)
|
135
|
+
@options[:site] + @options[:rest_base_path] + api
|
136
|
+
end
|
137
|
+
|
138
|
+
def request(path, form_params = {})
|
139
|
+
puts "\nREQ: #{path}"
|
140
|
+
@request_client.request(:post, path, '', default_headers(), form_params)
|
141
|
+
end
|
142
|
+
|
143
|
+
def default_headers()
|
144
|
+
{ 'Content-type' => 'application/x-www-form-urlencoded' }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright (c) 2015, Hothza
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
25
|
+
require 'net/https'
|
26
|
+
require 'cgi/cookie'
|
27
|
+
|
28
|
+
module Fbox
|
29
|
+
class HttpClient
|
30
|
+
attr_reader :options
|
31
|
+
|
32
|
+
def initialize(options)
|
33
|
+
@options = options
|
34
|
+
@options.freeze
|
35
|
+
@cookies = {}
|
36
|
+
end
|
37
|
+
|
38
|
+
def make_request(http_method, path, body='', headers={}, form_params = {})
|
39
|
+
request = Net::HTTP.const_get(http_method.to_s.capitalize).new(path, headers)
|
40
|
+
request.body = body unless body.nil?
|
41
|
+
add_cookies(request) if options[:use_cookies]
|
42
|
+
request.set_form_data(form_params) if !form_params.empty? && http_method.to_s.capitalize == 'Post'
|
43
|
+
|
44
|
+
response = http_conn(uri).request(request)
|
45
|
+
store_cookies(response) if options[:use_cookies]
|
46
|
+
response
|
47
|
+
end
|
48
|
+
|
49
|
+
def http_conn(uri)
|
50
|
+
if @options[:proxy_address]
|
51
|
+
http_class = Net::HTTP::Proxy(@options[:proxy_address], @options[:proxy_port] ? @options[:proxy_port] : 80)
|
52
|
+
else
|
53
|
+
http_class = Net::HTTP
|
54
|
+
end
|
55
|
+
http_conn = http_class.new(uri.host, uri.port)
|
56
|
+
http_conn.use_ssl = @options[:use_ssl]
|
57
|
+
http_conn.verify_mode = @options[:ssl_verify_mode]
|
58
|
+
http_conn
|
59
|
+
end
|
60
|
+
|
61
|
+
def uri
|
62
|
+
URI.parse(@options[:site])
|
63
|
+
end
|
64
|
+
|
65
|
+
def request(*args)
|
66
|
+
response = make_request(*args)
|
67
|
+
raise HTTPError.new(response) unless response.kind_of?(Net::HTTPSuccess)
|
68
|
+
response
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
def store_cookies(response)
|
73
|
+
cookies = response.get_fields('set-cookie')
|
74
|
+
if cookies
|
75
|
+
cookies.each do |cookie|
|
76
|
+
data = CGI::Cookie.parse(cookie)
|
77
|
+
data.delete('Path')
|
78
|
+
@cookies.merge!(data)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def add_cookies(request)
|
84
|
+
cookie_array = @cookies.values.map { |cookie| cookie.to_s }
|
85
|
+
request.add_field('Cookie', cookie_array.join('; ')) if cookie_array.any?
|
86
|
+
request
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/fbox/version.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Copyright (c) 2015, Hothza
|
2
|
+
# All rights reserved.
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without
|
5
|
+
# modification, are permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# * Redistributions of source code must retain the above copyright notice, this
|
8
|
+
# list of conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
# this list of conditions and the following disclaimer in the documentation
|
12
|
+
# and/or other materials provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
15
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
16
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
17
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
18
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
19
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
20
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
21
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
22
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
23
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
24
|
+
|
25
|
+
module Fbox
|
26
|
+
VERSION = "0.1.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fbox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hothza
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coins_address_validator
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- hothza@users.noreply.github.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- fbox.gemspec
|
85
|
+
- lib/fbox.rb
|
86
|
+
- lib/fbox/client.rb
|
87
|
+
- lib/fbox/http_client.rb
|
88
|
+
- lib/fbox/version.rb
|
89
|
+
homepage: https://github.com/Hothza/fbox
|
90
|
+
licenses:
|
91
|
+
- BSD
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.8
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Fbox - FaucetBox REST API helper. It allows you to integrate FaucetBox API
|
113
|
+
in an easy way in your RubyOnRails application.
|
114
|
+
test_files: []
|