Class: Base
- Inherits:
-
Object
show all
- Defined in:
- lib/blocksdk_ruby/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(api_token) ⇒ Base
Returns a new instance of Base.
7
8
9
|
# File 'lib/blocksdk_ruby/base.rb', line 7
def initialize(api_token)
@api_token = api_token
end
|
Instance Attribute Details
#api_token ⇒ Object
Returns the value of attribute api_token.
6
7
8
|
# File 'lib/blocksdk_ruby/base.rb', line 6
def api_token
@api_token
end
|
Instance Method Details
#getHashType(request = {}) ⇒ Object
15
16
17
|
# File 'lib/blocksdk_ruby/base.rb', line 15
def getHashType(request = {})
return request("GET","/auto/" + request['hash'] + "/type")
end
|
#getUsage(request = {}) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/blocksdk_ruby/base.rb', line 19
def getUsage(request = {})
if request["start_date"].to_s.empty?
d = Time.now - 604800
request['start_date'] = d.strftime("%Y-%m-%d")
end
if request["end_date"].to_s.empty?
d = Time.now
request['end_date'] = d.strftime("%Y-%m-%d")
end
return request("GET","/usage",{"start_date"=> request['start_date'],"end_date"=> request['end_date']})
end
|
#listPrice(request = {}) ⇒ Object
11
12
13
|
# File 'lib/blocksdk_ruby/base.rb', line 11
def listPrice(request = {})
return request("GET","/price")
end
|
#request(method, path, data = {}) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/blocksdk_ruby/base.rb', line 35
def request(method,path,data = {})
url = "https://api.blocksdk.com/v1" + path
if method == "GET" and data.size > 0
url += "?"
data.each do |key, value|
if value == true
url += key + "=true&"
elsif value == false
url += key + "=false&"
else
url += key+ "=" + value.to_s + "&"
end
end
end
if method == "POST"
response = HTTParty.post(url, :data => data, :headers => { 'Content-Type': 'application/json','x-api-key': @api_token})
else
response = HTTParty.get(url,:headers => { 'Content-Type': 'application/json','x-api-key': @api_token})
end
= response.
body = JSON.parse(response.body)
["statusCode"] = response.code
begin
body["HTTP_HEADER"] =
rescue
body_dict = {}
for i in 0..(body.length - 1)
ind = i.to_s
body_dict[ind] = body[i]
end
body = body_dict
body["HTTP_HEADER".to_s] =
end
return body
end
|