tapbot 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1e15f05fc034d20ae22e1ed3ffd827b314305634
4
+ data.tar.gz: 45ad5b318a1965aac0b081b43c6ec0832d72e619
5
+ SHA512:
6
+ metadata.gz: 00875333f29d1006f55e47cbea9ea324b0dd9f9e127bcc6ae6e4969a3ef05f87f36125dbcc1da16efa04531e241c2596183e06880a1319f37e9df7957389da58
7
+ data.tar.gz: 38df0f610521e77a084f28685704a92250baf2f1e02298d634bf3b949414eb84dff1ef907f577e2910a283fb424ace9e03762a5577fbad01efb11f8d05aacfc5
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'httparty', '~> 0.13.7'
4
+ gem 'hashie', '~> 3.4', '>= 3.4.2'
5
+
6
+ # Specify your gem's dependencies in tapbot.gemspec
7
+ gemspec
data/README.md ADDED
@@ -0,0 +1,152 @@
1
+ # Tapbot
2
+
3
+ [![Build Status](https://travis-ci.org/Tapbot/tapbot-ruby.svg?branch=master)](https://travis-ci.org/Tapbot/tapbot-ruby)
4
+ [![Code Climate](https://codeclimate.com/github/Tapbot/tapbot-ruby/badges/gpa.svg)](https://codeclimate.com/github/Tapbot/tapbot-ruby)
5
+
6
+ Official Tapbot API ruby gem.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'tapbot'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install tapbot
23
+
24
+ ## Usage
25
+
26
+ ###Client
27
+ First of all you should initialize a Tapbot client with your rest-token and secret.
28
+ ```ruby
29
+ client = Tapbot.client(rest_token: "your-token-here", rest_secret: "your-secret-here")
30
+ ```
31
+ ###User profiles
32
+ ```ruby
33
+ profile = client.profile("username")
34
+ ```
35
+ Profile object
36
+ ```ruby
37
+ profile.username => user username
38
+ profile.firstname => user first name
39
+ profile.lastname => user last name
40
+ profile.payment_address => user payment address
41
+ profile.bio => user bio
42
+ ```
43
+ ###Me
44
+ ```ruby
45
+ me = client.me
46
+ ```
47
+ Me object:
48
+ ```ruby
49
+ me.username => my username
50
+ me.firstname => user first name
51
+ me.lastname => user last name
52
+ me.payment_address => user payment address
53
+ me.bio => user bio
54
+ me.email => my email
55
+ me.balance => my balance
56
+ ```
57
+ ###Prices
58
+ ```ruby
59
+ price = client.price
60
+ ```
61
+ Price object
62
+ ```ruby
63
+ price.taps
64
+ price.btc
65
+ price.usd
66
+ ```
67
+ ###Transactions list
68
+ ```ruby
69
+ transactions = client.transaction_list(paginate: 10, page: 5) # optional paginate and page options
70
+ ```
71
+ Transactions list object
72
+ ```ruby
73
+ transactions.page
74
+ transactions.per_page
75
+ transactions.total_pages
76
+ transactions.total_transactions
77
+ transactions.transactions
78
+ ```
79
+ ###Transaction details
80
+ ```ruby
81
+ transaction = client.transaction_details("transaction-id")
82
+ ```
83
+ Transaction object
84
+ ```ruby
85
+ transaction.transaction_id
86
+ transaction.from
87
+ transaction.to
88
+ transaction.amount
89
+ transaction.date
90
+ transaction.comments
91
+ ```
92
+ ###Create a Transaction
93
+ ```ruby
94
+ transaction = client.create_transaction("username", amount) # transaction destination username
95
+ ```
96
+ If everithing is ok it should return a Transaction object
97
+ ```ruby
98
+ transaction.transaction_id
99
+ transaction.from
100
+ transaction.to
101
+ transaction.amount
102
+ transaction.date
103
+ transaction.comments
104
+ ```
105
+ Otherwise it should raise a Tapbot::Error with a concrete message
106
+ ###Exchange details
107
+ ```ruby
108
+ exchange = client.exchange_details("exchange-id")
109
+ ```
110
+ Exchange object
111
+ ```ruby
112
+ exchange.exchange_id
113
+ exchange.btc_address
114
+ exchange.status
115
+ exchange.from
116
+ exchange.to
117
+ exchange.from_amount
118
+ exchange.to_amount
119
+ exchange.date
120
+ ```
121
+ ###Create an Exchange
122
+ ```ruby
123
+ exchange = client.create_exchange(amount, "btc-address") # TAP amount to exchange to BTC and your Wallet address
124
+ ```
125
+ If everithing is ok it should return a Exchange object
126
+ ```ruby
127
+ exchange.exchange_id
128
+ exchange.btc_address
129
+ exchange.status
130
+ exchange.from
131
+ exchange.to
132
+ exchange.from_amount
133
+ exchange.to_amount
134
+ exchange.date
135
+ ```
136
+ Otherwise it should raise a Tapbot::Error with a concrete message
137
+
138
+ ## Development
139
+
140
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
141
+
142
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
143
+
144
+ ## Contributing
145
+
146
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tapbot/tapbot-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
147
+
148
+
149
+ ## License
150
+
151
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
152
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/lib/tapbot/api.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Tapbot
2
+ class Api
3
+
4
+ attr_accessor *Configuration::VALID_OPTIONS_KEYS
5
+
6
+ def initialize(options={})
7
+ options = Tapbot.options.merge(options)
8
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
9
+ send("#{key}=", options[key])
10
+ end
11
+ end
12
+
13
+ def config
14
+ conf = {}
15
+ Configuration::VALID_OPTIONS_KEYS.each do |key|
16
+ conf[key] = send key
17
+ end
18
+ conf
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Tapbot
2
+ class Client
3
+ module Exchanges
4
+
5
+ def exchange_details(id)
6
+ response = self.class.get("/exchanges/#{id}", headers: auth_headers("/exchanges/#{id}"))
7
+ raise Tapbot::Error, response["errors"][0] unless response.success?
8
+ response
9
+ end
10
+
11
+ def create_exchange(amount, address)
12
+ response = self.class.post("/exchanges", { :body => {:exchange => { from_amount: amount, btc_address: address }}.to_json, headers: auth_headers("/exchanges", { :exchange => { from_amount: amount, btc_address: address }}.to_json)})
13
+ raise Tapbot::Error, response["errors"][0] unless response.success?
14
+ response
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module Tapbot
2
+ class Client
3
+ module Prices
4
+
5
+ def price
6
+ response = self.class.get("/price", headers: auth_headers("/price"))
7
+ raise Tapbot::Error, response["errors"][0] unless response.success?
8
+ response
9
+ end
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Tapbot
2
+ class Client
3
+ module Transactions
4
+
5
+ def transaction_list(options={})
6
+ page = options[:page] || 1
7
+ paginate = options[:paginate] || 50
8
+ response = self.class.get("/transactions?paginate=#{paginate}&page=#{page}", headers: auth_headers("/transactions?paginate=#{paginate}&page=#{page}"))
9
+ raise Tapbot::Error, response["errors"][0] unless response.success?
10
+ response
11
+ end
12
+
13
+ def transaction_details(id)
14
+ response = self.class.get("/transactions/#{id}", headers: auth_headers("/transactions/#{id}"))
15
+ raise Tapbot::Error, response["errors"][0] unless response.success?
16
+ response
17
+ end
18
+
19
+ def create_transaction(to, amount, comments="")
20
+ response = self.class.post("/transactions", { :body => {:transaction => { to: to, amount: amount, comments: comments }}.to_json, headers: auth_headers("/transactions", { :transaction => { to: to, amount: amount, comments: comments }}.to_json)})
21
+ raise Tapbot::Error, response["errors"][0] unless response.success?
22
+ response
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ module Tapbot
2
+ class Client
3
+ module Users
4
+
5
+ def profile(username)
6
+ response = self.class.get("/users/#{username}")
7
+ raise Tapbot::Error, response["errors"][0] unless response.success?
8
+ response
9
+ end
10
+
11
+ def me
12
+ response = self.class.get("/users/me", headers: auth_headers("/users/me"))
13
+ raise Tapbot::Error, response["errors"][0] unless response.success?
14
+ response
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,37 @@
1
+ module Tapbot
2
+ class Client < Api
3
+ Dir[File.expand_path('../client/*.rb', __FILE__)].each{|f| require f}
4
+
5
+ include HTTParty
6
+
7
+ parser Tapbot::Parser
8
+
9
+ base_uri Tapbot::Configuration::BASE_URI
10
+
11
+ def auth_headers(url, body="")
12
+ ts = Time.now.to_i.to_s
13
+ if rest_secret && rest_token && url
14
+ signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'),
15
+ rest_secret,
16
+ rest_token + ts + (Tapbot::Configuration::BASE_URI + url) + body.to_s)
17
+
18
+
19
+ {
20
+ "Content-Type" => "application/json",
21
+ "Accept" => "application/json",
22
+ "User-Agent" => Tapbot::Configuration::USER_AGENT,
23
+ 'TP-REST-TOKEN' => rest_token,
24
+ 'TP-ACCESS-SIGNATURE' => signature,
25
+ 'TP-ACCESS-TIMESTAMP' => ts,
26
+ 'TP-API-VERSION' => Tapbot::Configuration::API_VERSION }
27
+ else
28
+ raise Tapbot::Error, "Invalid credentials"
29
+ end
30
+ end
31
+
32
+ include Tapbot::Client::Users
33
+ include Tapbot::Client::Prices
34
+ include Tapbot::Client::Transactions
35
+ include Tapbot::Client::Exchanges
36
+ end
37
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path('../version', __FILE__)
2
+
3
+ module Tapbot
4
+ module Configuration
5
+ VALID_OPTIONS_KEYS = [:rest_token, :rest_secret].freeze
6
+ BASE_URI = 'https://api.tapbot.com/v1'.freeze
7
+ USER_AGENT = "tapbot-ruby #{Tapbot::VERSION}".freeze
8
+ API_VERSION = "v1"
9
+
10
+ attr_accessor *VALID_OPTIONS_KEYS
11
+
12
+ def configure
13
+ yield self
14
+ end
15
+
16
+ def options
17
+ VALID_OPTIONS_KEYS.inject({}) do |option, key|
18
+ option.merge!(key => send(key))
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module Tapbot
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,15 @@
1
+ module Tapbot
2
+ class Parser < HTTParty::Parser
3
+ SupportedFormats = {'application/json' => :json}
4
+
5
+ def initialize(body, format)
6
+ @body = body
7
+ @format = format
8
+ end
9
+
10
+ def json
11
+ Hashie::Mash.new(JSON.parse(body))
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Tapbot
2
+ VERSION = "0.1.0"
3
+ end
data/lib/tapbot.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'httparty'
2
+ require 'hashie'
3
+ require "tapbot/version"
4
+ require "tapbot/error"
5
+ require "tapbot/configuration"
6
+ require "tapbot/api"
7
+ require "tapbot/parser"
8
+ require "tapbot/client"
9
+
10
+ module Tapbot
11
+ extend Configuration
12
+
13
+ def self.client(options={})
14
+ Tapbot::Client.new(options)
15
+ end
16
+
17
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'tapbot'
3
+ require 'rspec'
4
+ require 'webmock/rspec'
5
+
6
+ RSpec.configure do |config|
7
+ config.include WebMock::API
8
+ end
9
+
10
+ def fixture_path
11
+ File.expand_path("../fixtures", __FILE__)
12
+ end
13
+
14
+ def fixture(file)
15
+ File.new(fixture_path + '/' + file)
16
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tapbot do
4
+ it 'has a version number' do
5
+ expect(Tapbot::VERSION).not_to be nil
6
+ end
7
+
8
+ describe "CLIENT" do
9
+ it "should be a Tapbot::Client" do
10
+ expect(Tapbot.client).to be_a Tapbot::Client
11
+ end
12
+ end
13
+
14
+ describe "BASE URI" do
15
+ it "should return the default base uri" do
16
+ expect(Tapbot::Configuration::BASE_URI).to eq("https://api.tapbot.com/v1")
17
+ end
18
+ end
19
+
20
+ describe "API VERSION" do
21
+ it "should return the default API version" do
22
+ expect(Tapbot::Configuration::API_VERSION).to eq("v1")
23
+ end
24
+ end
25
+
26
+ describe "User Agent" do
27
+ it "should return the default API version" do
28
+ expect(Tapbot::Configuration::USER_AGENT).to eq("tapbot-ruby #{Tapbot::VERSION}")
29
+ end
30
+ end
31
+
32
+ describe "Configuration" do
33
+ Tapbot::Configuration::VALID_OPTIONS_KEYS.each do |key|
34
+ it "should set the #{key}" do
35
+ Tapbot.configure do |config|
36
+ config.send("#{key}=", key)
37
+ expect(Tapbot.send(key)).to eq(key)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tapbot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Ramirez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-30 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.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.13.7
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.13.7
83
+ - !ruby/object:Gem::Dependency
84
+ name: hashie
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 3.4.2
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '3.4'
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 3.4.2
103
+ description: Tapbot api gem
104
+ email:
105
+ - david@davidrv.com
106
+ executables: []
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - Gemfile
111
+ - README.md
112
+ - Rakefile
113
+ - lib/tapbot.rb
114
+ - lib/tapbot/api.rb
115
+ - lib/tapbot/client.rb
116
+ - lib/tapbot/client/exchanges.rb
117
+ - lib/tapbot/client/prices.rb
118
+ - lib/tapbot/client/transactions.rb
119
+ - lib/tapbot/client/users.rb
120
+ - lib/tapbot/configuration.rb
121
+ - lib/tapbot/error.rb
122
+ - lib/tapbot/parser.rb
123
+ - lib/tapbot/version.rb
124
+ - spec/spec_helper.rb
125
+ - spec/tapbot_spec.rb
126
+ homepage: https://tapbot.readme.io/
127
+ licenses:
128
+ - MIT
129
+ metadata:
130
+ allowed_push_host: https://rubygems.org
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.4.8
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Tapbot api gem
151
+ test_files: []