Class: Lita::Handlers::TipbotApi
- Inherits:
-
Object
- Object
- Lita::Handlers::TipbotApi
- Defined in:
- lib/lita/handlers/tipbot.rb
Instance Attribute Summary collapse
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
-
#base_url ⇒ Object
Returns the value of attribute base_url.
-
#log ⇒ Object
Returns the value of attribute log.
Instance Method Summary collapse
- #address(hash) ⇒ Object
- #balance(hash) ⇒ Object
- #history(hash) ⇒ Object
-
#initialize(params) ⇒ TipbotApi
constructor
A new instance of TipbotApi.
- #register(hash) ⇒ Object
- #rest_get(url) ⇒ Object
- #rest_post(url, payload) ⇒ Object
- #tip(giver_hash, receiver_hash, amount) ⇒ Object
- #withdraw(src_hash, dest_address) ⇒ Object
Constructor Details
#initialize(params) ⇒ TipbotApi
Returns a new instance of TipbotApi.
11 12 13 14 15 |
# File 'lib/lita/handlers/tipbot.rb', line 11 def initialize(params) @base_url = params[:url] @auth_token = params[:auth_token] @log = params[:log] end |
Instance Attribute Details
#auth_token ⇒ Object
Returns the value of attribute auth_token.
9 10 11 |
# File 'lib/lita/handlers/tipbot.rb', line 9 def auth_token @auth_token end |
#base_url ⇒ Object
Returns the value of attribute base_url.
9 10 11 |
# File 'lib/lita/handlers/tipbot.rb', line 9 def base_url @base_url end |
#log ⇒ Object
Returns the value of attribute log.
9 10 11 |
# File 'lib/lita/handlers/tipbot.rb', line 9 def log @log end |
Instance Method Details
#address(hash) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/lita/handlers/tipbot.rb', line 40 def address(hash) url = "#{base_url}/wallet/#{hash}" resp = rest_get url data = JSON.parse resp.body data['address'] end |
#balance(hash) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/lita/handlers/tipbot.rb', line 47 def balance(hash) url = "#{base_url}/wallet/#{hash}/balance" resp = rest_get url data = JSON.parse resp.body data['balance'] # TODO: check for NaN end |
#history(hash) ⇒ Object
54 55 56 57 58 |
# File 'lib/lita/handlers/tipbot.rb', line 54 def history(hash) url = "#{base_url}/wallet/#{hash}/history" resp = rest_get url resp.body end |
#register(hash) ⇒ Object
34 35 36 37 38 |
# File 'lib/lita/handlers/tipbot.rb', line 34 def register(hash) url = "#{base_url}/wallet/#{hash}/register" resp = rest_get url resp.body end |
#rest_get(url) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/lita/handlers/tipbot.rb', line 17 def rest_get(url) headers = { 'Authorization' => auth_token, 'Accept' => 'application/json' } HTTParty.get(url, headers: headers) end |
#rest_post(url, payload) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/lita/handlers/tipbot.rb', line 25 def rest_post(url, payload) headers = { 'Authorization' => auth_token, 'Accept' => 'application/json', 'Content-Type' => 'application/json' } HTTParty.post(url, headers: headers, body: payload) end |
#tip(giver_hash, receiver_hash, amount) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lita/handlers/tipbot.rb', line 60 def tip(giver_hash, receiver_hash, amount) url = "#{base_url}/wallet/tip" payload = { from: giver_hash, to: reciever_hash, amount: amount }.to_json resp = rest_post url, payload resp.body end |
#withdraw(src_hash, dest_address) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/lita/handlers/tipbot.rb', line 73 def withdraw(src_hash, dest_address) url = "#{base_url}/wallet/#{src_hash}/withdraw/#{dest_address}" resp = rest_get url data = JSON.parse(resp.body) data['message'] end |