btcjammer 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 +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +138 -0
- data/Rakefile +9 -0
- data/btcjammer.gemspec +31 -0
- data/lib/btcjammer.rb +74 -0
- data/lib/btcjammer/automatic_plan_templates.rb +13 -0
- data/lib/btcjammer/automatic_plans.rb +24 -0
- data/lib/btcjammer/currencies.rb +13 -0
- data/lib/btcjammer/employment_statuses.rb +13 -0
- data/lib/btcjammer/listings.rb +39 -0
- data/lib/btcjammer/national_id_types.rb +13 -0
- data/lib/btcjammer/payment_types.rb +13 -0
- data/lib/btcjammer/submit_documents.rb +32 -0
- data/lib/btcjammer/terms.rb +13 -0
- data/lib/btcjammer/users.rb +71 -0
- data/lib/btcjammer/version.rb +4 -0
- data/test/automatic_plan_templates_test.rb +19 -0
- data/test/currencies_test.rb +26 -0
- data/test/employment_statuses_test.rb +19 -0
- data/test/fixtures/automatic_plan_templates.yml +54 -0
- data/test/fixtures/currencies.yml +95 -0
- data/test/fixtures/employee_statuses.yml +61 -0
- data/test/fixtures/national_id_types.yml +79 -0
- data/test/fixtures/payment_types.yml +99 -0
- data/test/fixtures/terms.yml +100 -0
- data/test/listings_test.rb +70 -0
- data/test/national_id_types_test.rb +20 -0
- data/test/payment_types_test.rb +22 -0
- data/test/submit_documents_test.rb +38 -0
- data/test/terms_test.rb +21 -0
- data/test/test_helper.rb +9 -0
- data/test/users_test.rb +130 -0
- metadata +221 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77186d34b882bc759e332ed8e09454052e666a3a
|
4
|
+
data.tar.gz: ad9e1ba6a5316923890965a180a42ef11df5d1c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f163f27066cc5aba1e73586c45160975e43e1711cbec70780f38b74ba428642eb3ecdc12a0bb45464e0ebf9bb595790c4e837ee68ac14840ce7fb4a86e0a0661
|
7
|
+
data.tar.gz: 2c17ad699ff8d1d2d1e65c30d74c69eddfc0cd6e3f17c00af7399f41b970da008b1aee3fe5b541eb93ae620444a4fb3e45af8b4b7c498ce217542c9d0d43986a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Chris Cacciatore
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# btcjammer
|
2
|
+
|
3
|
+
A Ruby interface to the BTCJam API.
|
4
|
+
|
5
|
+
## Disclaimer
|
6
|
+
|
7
|
+
Note, investing with BTCJam involves risk. Use this API at your own risk.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'btcjammer'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install btcjammer
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
After installation and without further configuration you can use the following API methods:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'btcjammer'
|
31
|
+
|
32
|
+
# returns an array of currencies
|
33
|
+
BTCJammer::Currencies.all
|
34
|
+
|
35
|
+
# returns an array of employment types
|
36
|
+
BTCJammer::EmploymentTypes.all
|
37
|
+
|
38
|
+
# returns an array of national ID types
|
39
|
+
BTCJammer::NationalIDTypes.all
|
40
|
+
|
41
|
+
# returns an array of payment types
|
42
|
+
BTCJammer::PaymentTypes.all
|
43
|
+
|
44
|
+
# returns an array of automatic plan templates
|
45
|
+
BTCJammer::AutomaticPlanTemplates.all
|
46
|
+
```
|
47
|
+
|
48
|
+
If you want to ask more interesting things, then you'll need a BCTJam account and need [to register an app](https://btcjam.com/oauth/applications) with BTCJam. Finally, grab your Application ID and Secret:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'btcjammer'
|
52
|
+
|
53
|
+
BTCJammer.configure do |config|
|
54
|
+
config.client_id = "<YOUR APPLICATION ID>"
|
55
|
+
config.client_secret = "<YOUR SECRET>"
|
56
|
+
end
|
57
|
+
|
58
|
+
# returns an array of listings (not sure yet if it is paginated and if so how)
|
59
|
+
BTCJammer::Listings.all
|
60
|
+
|
61
|
+
# creates a new user (not very well tested currently)
|
62
|
+
BTCJammer::Users.create "bilbo.baggins@shire.com", "Elevensies11"
|
63
|
+
```
|
64
|
+
|
65
|
+
Lastly, the following API methods require an authenticated user:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
require 'btcjammer'
|
69
|
+
BTCJammer.configure do |config|
|
70
|
+
config.client_id = "<YOUR APPLICATION ID>"
|
71
|
+
config.client_secret = "<YOUR SECRET>"
|
72
|
+
config.scopes = [:basic_profile, :extended_profile, :make_loan,
|
73
|
+
:identity_information, :address_information, :income_information,
|
74
|
+
:invest, :trade, :withdraw, :submit_documents, :manage_references]
|
75
|
+
config.redirect_uri = "<YOUR REGISTERED CALLBACK URL>"
|
76
|
+
end
|
77
|
+
|
78
|
+
# send the user here to authorize
|
79
|
+
auth = BTCJammer::OAuth.new
|
80
|
+
|
81
|
+
url = auth.authorization_url
|
82
|
+
|
83
|
+
# assuming you get a code back
|
84
|
+
code = "<CODE YOU RECEIVED IN CALLBACK>"
|
85
|
+
access_token = auth.get_access_token(code)
|
86
|
+
|
87
|
+
# or if you have a saved token
|
88
|
+
access_token = BTCJammer::OAuth.from_token token
|
89
|
+
|
90
|
+
# retrieve the auth'd user's profile
|
91
|
+
BTCJammer::Users.profile access_token.token
|
92
|
+
|
93
|
+
# retrieve the auth'd user's payables
|
94
|
+
BTCJammer::Users.payables access_token.token
|
95
|
+
|
96
|
+
# retrieve the auth'd user's receivables
|
97
|
+
BTCJammer::Users.receivables access_token.token
|
98
|
+
|
99
|
+
# retrieve the auth'd user's credit checks
|
100
|
+
BTCJammer::Users.credit_checks access_token.token
|
101
|
+
|
102
|
+
# retrieve the auth'd user's addr checks
|
103
|
+
BTCJammer::Users.addr_checks access_token.token
|
104
|
+
|
105
|
+
# retrieve the auth'd user's identity checks
|
106
|
+
BTCJammer::Users.identity_checks access_token.token
|
107
|
+
|
108
|
+
# retrieve the auth'd user's open listings
|
109
|
+
BTCJammer::Users.open_listings access_token.token
|
110
|
+
|
111
|
+
# invest in a listing
|
112
|
+
BTCJammer::User.invest access_token.token, {:listing_id => 123, :amount => 0.1}
|
113
|
+
|
114
|
+
# create a new listing
|
115
|
+
params = {
|
116
|
+
loan_purpose_id: 1,
|
117
|
+
currency_id: 2,
|
118
|
+
amount: 0.01,
|
119
|
+
term_days: 123,
|
120
|
+
payment_type_id: 3,
|
121
|
+
locale_id: 4,
|
122
|
+
title: 'A new listing',
|
123
|
+
description: 'Sweet!'
|
124
|
+
}
|
125
|
+
BTCJammer::Listings.create access_token.token, params
|
126
|
+
```
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
|
130
|
+
If you would like ideas on what to work on, then please send me a line. There are plenty of opportunities to refactor code and extend the current functionality.
|
131
|
+
|
132
|
+
1. Fork it ( https://github.com/cacciatc/btcjammer/fork )
|
133
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
134
|
+
3. Write tests
|
135
|
+
4. Run rubocop
|
136
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
137
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
138
|
+
7. Create a new Pull Request
|
data/Rakefile
ADDED
data/btcjammer.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'btcjammer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'btcjammer'
|
8
|
+
spec.version = BTCJammer::VERSION
|
9
|
+
spec.authors = ['Chris Cacciatore']
|
10
|
+
spec.email = ['chris.cacciatore@dullahansoft.com']
|
11
|
+
spec.summary = 'A gem to wrap the BTCJam API.'
|
12
|
+
spec.description = 'A simple wrapper for BTCJam API calls with support for user authenticated API calls.'
|
13
|
+
spec.homepage = 'https://github.com/cacciatc/btcjammer'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
24
|
+
spec.add_development_dependency 'vcr', '~> 2.9'
|
25
|
+
spec.add_development_dependency 'webmock', '~> 1.21'
|
26
|
+
spec.add_development_dependency 'rubocop', '~> 0.34'
|
27
|
+
|
28
|
+
spec.add_dependency 'faraday', '~> 0.9'
|
29
|
+
spec.add_dependency 'json', '~> 1.8'
|
30
|
+
spec.add_dependency 'oauth2', '~> 1.0'
|
31
|
+
end
|
data/lib/btcjammer.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
require 'oauth2'
|
3
|
+
|
4
|
+
require_relative 'btcjammer/version'
|
5
|
+
require_relative 'btcjammer/currencies'
|
6
|
+
require_relative 'btcjammer/payment_types'
|
7
|
+
require_relative 'btcjammer/automatic_plan_templates'
|
8
|
+
require_relative 'btcjammer/employment_statuses'
|
9
|
+
require_relative 'btcjammer/national_id_types'
|
10
|
+
require_relative 'btcjammer/listings'
|
11
|
+
require_relative 'btcjammer/users'
|
12
|
+
require_relative 'btcjammer/terms'
|
13
|
+
require_relative 'btcjammer/submit_documents'
|
14
|
+
require_relative 'btcjammer/automatic_plans'
|
15
|
+
|
16
|
+
# Contains all the BTCJam API magic
|
17
|
+
module BTCJammer
|
18
|
+
API_URL = 'https://btcjam.com/api/v1'
|
19
|
+
API_PUBLIC_URL = 'https://btcjam.com'
|
20
|
+
|
21
|
+
# Holds info for oauth config including BTCJam scopes
|
22
|
+
module Configuration
|
23
|
+
attr_accessor :client_id, :client_secret, :scopes, :redirect_uri
|
24
|
+
|
25
|
+
def configure
|
26
|
+
yield self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Helper methods around OAuth2
|
31
|
+
class OAuth
|
32
|
+
include OAuth2
|
33
|
+
attr_accessor :client
|
34
|
+
def initialize
|
35
|
+
@client = Client.new(BTCJam.client_id, BTCJam.client_secret,
|
36
|
+
site: API_PUBLIC_URL)
|
37
|
+
end
|
38
|
+
|
39
|
+
def authorization_url
|
40
|
+
@client.auth_code.authorize_url(redirect_uri: BTCJam.redirect_uri,
|
41
|
+
scope: BTCJam.scopes.join(' '))
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_access_token(code)
|
45
|
+
@client.auth_code.get_token(code, redirect_uri: BTCJam.redirect_uri)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.from_token(token)
|
49
|
+
auth = OAuth.new
|
50
|
+
OAuth2::AccessToken.new(auth.client, token)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.get_client(access_token)
|
55
|
+
id = ENV['BTCJAM_CLIENT_ID']
|
56
|
+
secret = ENV['BTCJAM_CLIENT_SECRET']
|
57
|
+
client = OAuth2::Client.new id, secret, site: 'https://btcjam.com'
|
58
|
+
|
59
|
+
OAuth2::AccessToken.new client, access_token
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.api_call(access_token, symbol, type)
|
63
|
+
token = get_client access_token
|
64
|
+
response = token.get("#{API_URL}/#{symbol}.json")
|
65
|
+
|
66
|
+
if type == :object
|
67
|
+
OpenStruct.new JSON.parse(response.body)
|
68
|
+
elsif type == :array
|
69
|
+
JSON.parse(response.body).collect { |i| OpenStruct.new i }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
extend Configuration
|
74
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class AutomaticPlanTemplates
|
8
|
+
def self.all
|
9
|
+
response = Faraday.get("#{API_PUBLIC_URL}/automatic_plan_templates.json")
|
10
|
+
JSON.parse(response.body).collect { |t| OpenStruct.new t }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class AutomaticPlans
|
8
|
+
def self.create(access_token, params)
|
9
|
+
token = BTCJammer.get_client access_token
|
10
|
+
response = token.post("#{API_URL}/automatic_plans.json", body: { automatic_plan: params.to_json })
|
11
|
+
|
12
|
+
result = OpenStruct.new JSON.parse(response.body)
|
13
|
+
OpenStruct.new(result.automatic_plan)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all(access_token)
|
17
|
+
token = BTCJammer.get_client access_token
|
18
|
+
response = token.get("#{API_URL}/automatic_plans.json")
|
19
|
+
|
20
|
+
result = OpenStruct.new JSON.parse(response.body)
|
21
|
+
result.collect { |r| OpenStruct.new r }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class Currencies
|
8
|
+
def self.all
|
9
|
+
response = Faraday.get("#{API_PUBLIC_URL}/currencies.json")
|
10
|
+
JSON.parse(response.body).collect { |c| OpenStruct.new c }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class EmploymentStatuses
|
8
|
+
def self.all
|
9
|
+
response = Faraday.get("#{API_PUBLIC_URL}/employment_statuses.json")
|
10
|
+
JSON.parse(response.body).collect { |t| OpenStruct.new t }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class Listings
|
8
|
+
def self.all
|
9
|
+
url = "#{API_URL}/"
|
10
|
+
url += "listings.json?appid=#{BTCJammer.client_id}&"
|
11
|
+
url += "secret=#{BTCJammer.client_secret}"
|
12
|
+
|
13
|
+
response = Faraday.get(url)
|
14
|
+
|
15
|
+
JSON.parse(response.body).collect do |c|
|
16
|
+
listing = OpenStruct.new c['listing']
|
17
|
+
listing.user = OpenStruct.new listing.user
|
18
|
+
|
19
|
+
listing
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.create(access_token, params)
|
24
|
+
token = BTCJammer.get_client access_token
|
25
|
+
response = token.post("#{API_URL}/listings.json", body: { listing: params.to_json })
|
26
|
+
|
27
|
+
result = OpenStruct.new JSON.parse(response.body)
|
28
|
+
OpenStruct.new(result.listing)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.create_lead(access_token, params)
|
32
|
+
token = BTCJammer.get_client access_token
|
33
|
+
response = token.post("#{API_URL}/lead_listings.json", body: { lead_listing: params.to_json })
|
34
|
+
|
35
|
+
result = OpenStruct.new JSON.parse(response.body)
|
36
|
+
OpenStruct.new(result.lead_listing)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class NationalIDTypes
|
8
|
+
def self.all
|
9
|
+
response = Faraday.get("#{API_PUBLIC_URL}/nationalid_types.json")
|
10
|
+
JSON.parse(response.body).collect { |t| OpenStruct.new t }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module BTCJammer
|
6
|
+
# https://btcjam.com/faq/api
|
7
|
+
class PaymentTypes
|
8
|
+
def self.all
|
9
|
+
response = Faraday.get("#{API_PUBLIC_URL}/payment_types.json")
|
10
|
+
JSON.parse(response.body).collect { |t| OpenStruct.new t }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|