Class: Xmrto::Transfer
- Inherits:
-
Object
show all
- Defined in:
- lib/xmrto/transfer.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(uuid = nil) ⇒ Transfer
Returns a new instance of Transfer.
12
13
14
|
# File 'lib/xmrto/transfer.rb', line 12
def initialize(uuid = nil)
self.uuid = uuid
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/xmrto/transfer.rb', line 36
def method_missing(m, *args, &block)
if instance_values.has_key?(m.to_s)
instance_values[m.to_s]
else
super
end
end
|
Instance Attribute Details
#state ⇒ Object
Returns the value of attribute state.
10
11
12
|
# File 'lib/xmrto/transfer.rb', line 10
def state
@state
end
|
#uuid ⇒ Object
Returns the value of attribute uuid.
10
11
12
|
# File 'lib/xmrto/transfer.rb', line 10
def uuid
@uuid
end
|
Class Method Details
.create(btc_address, btc_amount) ⇒ Object
16
17
18
|
# File 'lib/xmrto/transfer.rb', line 16
def self.create(btc_address, btc_amount)
new.create(btc_address, btc_amount)
end
|
.status(uuid) ⇒ Object
20
21
22
|
# File 'lib/xmrto/transfer.rb', line 20
def self.status(uuid)
new(uuid).update
end
|
Instance Method Details
#create(btc_address, btc_amount) ⇒ Object
24
25
26
27
28
29
|
# File 'lib/xmrto/transfer.rb', line 24
def create(btc_address, btc_amount)
request = post_request("/order_create/", { "btc_dest_address": btc_address, "btc_amount": btc_amount })
self.uuid = request["uuid"]
self.state = request["state"]
self
end
|
#livenet? ⇒ Boolean
48
49
50
|
# File 'lib/xmrto/transfer.rb', line 48
def livenet?
Xmrto.config.network == :livenet
end
|
#post_request(endpoint, args) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/xmrto/transfer.rb', line 52
def post_request(endpoint, args)
url = "#{base_url}#{endpoint}"
p "sending POST request to: #{url} with params: #{args.to_json}" if Xmrto.config.debug
response = HTTParty.post(url, body: args.to_json, headers: { 'Content-Type' => 'application/json' } )
if response["error"]
raise("Xmrto::Error#{response["error"][-3..-1]}".constantize, response["error_msg"] )
end
response
end
|
#testnet? ⇒ Boolean
44
45
46
|
# File 'lib/xmrto/transfer.rb', line 44
def testnet?
Xmrto.config.network == :testnet
end
|
#update ⇒ Object
31
32
33
34
|
# File 'lib/xmrto/transfer.rb', line 31
def update
fetch_status.map{|attr, value| instance_variable_set("@#{attr}", value) }
state
end
|