scalechain 1.0.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: ae6f281db35833d225a7ee87eb333519a9cde0eb
4
+ data.tar.gz: 1d1aa30190eaeb5c7279239656de7c1823736361
5
+ SHA512:
6
+ metadata.gz: 4ed0dcdaab2c42b3891e76a4ffd1c5be25888d0f71512aecc75214eebe8ce2f180769f645c47729736eadc6aff59ffd8e3fca9ad9ad5bb9f0b20a6fe71e4da8b
7
+ data.tar.gz: d52c76900b989af551e15966e6e001412a37508b994a8a9a5caf7e0b0acbb9f746ab10d8148699288f55876cd5162f8823dfc48b7cfeadb3813dc16c85c42674
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # The ScaleChain API for Ruby
2
+
3
+ The official Ruby library for the [ScaleChain API](https://docs.scalechain.io/).
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install scalechain
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ### Sign Up
14
+
15
+ The first thing you'll need to do is sign up for [ScaleChain Cloud](https://cloud.scalechain.io/signup).
16
+
17
+ ### Get API Key
18
+
19
+ Go to [Manage API](https://cloud.scalechain.io/keys) and click 'Add New API Key'.
20
+
21
+ ### Get an Access Token
22
+
23
+ ```ruby
24
+ # Import ScaleChain SDK
25
+ require 'scalechain'
26
+
27
+ key = "API-KEY"
28
+ secret = "API-SECRET"
29
+
30
+ auth = ScaleChain::AuthorizationController.new
31
+ config = ScaleChain::Configuration
32
+
33
+ response = auth.get_access_token_by_client_credential(key, secret)
34
+
35
+ config.o_auth_access_token = response["access_token"]
36
+ config.o_auth_refresh_token = response["refresh_token"]
37
+ ```
38
+
39
+ ## Making API Calls
40
+
41
+ ```ruby
42
+ block = ScaleChain::BlockController.new
43
+
44
+ response = block.get_block("latest", "mainnet")
45
+ puts response
46
+ ```
47
+
48
+ ## Switching to Testnet Blockchain
49
+
50
+ ```ruby
51
+ block = ScaleChain::BlockController.new
52
+
53
+ response = block.get_block("latest", "testnet")
54
+ puts response
55
+ ```
56
+
57
+ ## Handling exception
58
+
59
+ ```ruby
60
+ block = ScaleChain::BlockController.new
61
+
62
+ begin
63
+ response = block.get_block("latest", "testnet")
64
+ puts response
65
+ rescue Exception => exception
66
+ puts exception.response_body
67
+ end
68
+ ```
69
+
70
+ ## API Reference
71
+
72
+ Visit [docs.scalechain.io](https://docs.scalechain.io/).
@@ -0,0 +1,23 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class APIException < StandardError
5
+
6
+ # value store
7
+ attr_reader :response_code
8
+
9
+ # value store
10
+ attr_reader :response_body
11
+
12
+ # The HTTP response code from the API request
13
+ # @param [String] the reason for raising an exception
14
+ # @param [Numeric] the HTTP response code from the API request
15
+ # @param [Object] the HTTP unprased response from the API request
16
+ def initialize(reason, response_code, response_body)
17
+ super(reason)
18
+ @response_code = response_code
19
+ @response_body = response_body
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,82 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class APIHelper
5
+
6
+ # Replaces template parameters in the given url
7
+ # @param [String] The query string builder to replace the template parameters
8
+ # @param [Array] The parameters to replace in the url
9
+ def self.append_url_with_template_parameters(query_builder, parameters)
10
+ # perform parameter validation
11
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.is_a? String
12
+
13
+ # return if there are no parameters to replace
14
+ if parameters.nil? then
15
+ abort('no parameters to append')
16
+ end
17
+
18
+ # iterate and append parameters
19
+ parameters.map do |key, value|
20
+ replace_value = ''
21
+
22
+ if value.nil?
23
+ replace_value = ''
24
+ elsif value.is_a? Enumerable
25
+ replace_value = value.join("/")
26
+ else
27
+ replace_value = value.to_s
28
+ end
29
+
30
+ # find the template parameter and replace it with its value
31
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
32
+ end
33
+
34
+ query_builder
35
+ end
36
+
37
+ # Appends the given set of parameters to the given query string
38
+ # @param [String] The query string builder to replace the template parameters
39
+ # @param [Array] The parameters to append
40
+ def self.append_url_with_query_parameters(query_builder, parameters)
41
+ # perform parameter validation
42
+ raise ArgumentError, 'Given value for parameter \"query_builder\" is invalid.' unless query_builder.is_a? String
43
+
44
+ # return if there are no parameters to replace
45
+ if parameters.nil? then
46
+ abort('no parameters to append')
47
+ end
48
+
49
+ #remove any nil values
50
+ parameters = parameters.reject {|key, value| value.nil?}
51
+
52
+ # does the query string already has parameters
53
+ has_params = query_builder.include? '?'
54
+ separator = if has_params then '&' else '?' end
55
+
56
+ # append query with separator and parameters
57
+ query_builder << separator << URI.unescape(URI.encode_www_form(parameters))
58
+ end
59
+
60
+ # Validates and processes the given Url
61
+ # @param [String] The given Url to process
62
+ # @return [String] Pre-processed Url as string
63
+ def self.clean_url(url)
64
+ # perform parameter validation
65
+ raise ArgumentError, 'Invalid Url.' unless url.is_a? String
66
+
67
+ # ensure that the urls are absolute
68
+ matches = url.match(/^(https?:\/\/[^\/]+)/)
69
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
70
+
71
+ # get the http protocol match
72
+ protocol = matches[1]
73
+
74
+ # remove redundant forward slashes
75
+ query = url[protocol.length..-1].gsub(/\/\/+/, '/')
76
+
77
+ # return process url
78
+ return protocol + query;
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,22 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class Configuration
5
+
6
+ # The base Uri for API calls
7
+ @BASE_URI = "https://api.scalechain.io/v1"
8
+
9
+ # The OAuth 2.0 access token to be set before API calls
10
+ @o_auth_access_token = nil
11
+ @o_auth_refresh_token = nil
12
+
13
+
14
+ # create the getters and setters
15
+ class << self
16
+ attr_accessor :BASE_URI
17
+
18
+ attr_accessor :o_auth_access_token
19
+ attr_accessor :o_auth_refresh_token
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,189 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class AccountController
5
+
6
+ # Returns a collection of accounts for the authorized user.
7
+ # @return mixed response from the API call
8
+ def list
9
+ # the base uri for api requests
10
+ query_builder = Configuration.BASE_URI.dup
11
+
12
+ # prepare query string for API call
13
+ query_builder << "/accounts/list"
14
+
15
+ # validate and preprocess url
16
+ query_url = APIHelper.clean_url query_builder
17
+
18
+ # prepare headers
19
+ headers = {
20
+ "user-agent" => "APIMATIC 2.0",
21
+ "accept" => "application/json",
22
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
23
+ }
24
+
25
+ # invoke the API call request to fetch the response
26
+ response = Unirest.get query_url, headers:headers
27
+
28
+ #Error handling using HTTP status codes
29
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
30
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
31
+ end
32
+
33
+ response.body
34
+ end
35
+
36
+ # Returns details of an account.
37
+ # @param [String] id Required parameter: An account id
38
+ # @param [String] network Required parameter: Blockchain network
39
+ # @return mixed response from the API call
40
+ def show id, network
41
+ # the base uri for api requests
42
+ query_builder = Configuration.BASE_URI.dup
43
+
44
+ # prepare query string for API call
45
+ query_builder << "/accounts/{id}/show"
46
+
47
+ # process optional query parameters
48
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
49
+ "id" => id,
50
+ }
51
+
52
+ # validate and preprocess url
53
+ query_url = APIHelper.clean_url query_builder
54
+
55
+ # prepare headers
56
+ headers = {
57
+ "user-agent" => "APIMATIC 2.0",
58
+ "accept" => "application/json",
59
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
60
+ "network" => network
61
+ }
62
+
63
+ # invoke the API call request to fetch the response
64
+ response = Unirest.get query_url, headers:headers
65
+
66
+ #Error handling using HTTP status codes
67
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
68
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
69
+ end
70
+
71
+ response.body
72
+ end
73
+
74
+ # Returns a newly created account.
75
+ # @param [mixed] account Required parameter: An account object
76
+ # @return mixed response from the API call
77
+ def create account
78
+ # the base uri for api requests
79
+ query_builder = Configuration.BASE_URI.dup
80
+
81
+ # prepare query string for API call
82
+ query_builder << "/accounts/new"
83
+
84
+ # validate and preprocess url
85
+ query_url = APIHelper.clean_url query_builder
86
+
87
+ # prepare headers
88
+ headers = {
89
+ "user-agent" => "APIMATIC 2.0",
90
+ "accept" => "application/json",
91
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
92
+ }
93
+
94
+ # prepare parameters
95
+ parameters = {
96
+ "account" => account
97
+ }
98
+
99
+ # invoke the API call request to fetch the response
100
+ response = Unirest.post query_url, headers:headers, parameters:parameters
101
+
102
+ #Error handling using HTTP status codes
103
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
104
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
105
+ end
106
+
107
+ response.body
108
+ end
109
+
110
+ # Returns the deleted account id.
111
+ # @param [String] id Required parameter: An account id
112
+ # @return mixed response from the API call
113
+ def delete id
114
+ # the base uri for api requests
115
+ query_builder = Configuration.BASE_URI.dup
116
+
117
+ # prepare query string for API call
118
+ query_builder << "/accounts/delete"
119
+
120
+ # validate and preprocess url
121
+ query_url = APIHelper.clean_url query_builder
122
+
123
+ # prepare headers
124
+ headers = {
125
+ "user-agent" => "APIMATIC 2.0",
126
+ "accept" => "application/json",
127
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
128
+ }
129
+
130
+ # prepare parameters
131
+ parameters = {
132
+ "id" => id
133
+ }
134
+
135
+ # invoke the API call request to fetch the response
136
+ response = Unirest.delete query_url, headers:headers, parameters:parameters
137
+
138
+ #Error handling using HTTP status codes
139
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
140
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
141
+ end
142
+
143
+ response.body
144
+ end
145
+
146
+ # Send coins to an address and returns its transaction id.
147
+ # @param [String] account_id Required parameter: An account id
148
+ # @param [String] amount Required parameter: An amount to send
149
+ # @param [String] network Required parameter: Blockchain network
150
+ # @param [String] to_address Required parameter: An address to send
151
+ # @return mixed response from the API call
152
+ def send_coin account_id, amount, to_address, network
153
+ # the base uri for api requests
154
+ query_builder = Configuration.BASE_URI.dup
155
+
156
+ # prepare query string for API call
157
+ query_builder << "/accounts/send"
158
+
159
+ # validate and preprocess url
160
+ query_url = APIHelper.clean_url query_builder
161
+
162
+ # prepare headers
163
+ headers = {
164
+ "user-agent" => "APIMATIC 2.0",
165
+ "accept" => "application/json",
166
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
167
+ "network" => network
168
+ }
169
+
170
+ # prepare parameters
171
+ parameters = {
172
+ "account_id" => account_id,
173
+ "amount" => amount,
174
+ "to_address" => to_address
175
+ }
176
+
177
+ # invoke the API call request to fetch the response
178
+ response = Unirest.post query_url, headers:headers, parameters:parameters
179
+
180
+ #Error handling using HTTP status codes
181
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
182
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
183
+ end
184
+
185
+ response.body
186
+ end
187
+
188
+ end
189
+ end
@@ -0,0 +1,279 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class AddressController
5
+
6
+ # Returns basic balance details for an addresses.
7
+ # @param [String] address Required parameter: An address
8
+ # @param [String] network Required parameter: Blockchain network
9
+ # @return mixed response from the API call
10
+ def get_address address, network
11
+ # the base uri for api requests
12
+ query_builder = Configuration.BASE_URI.dup
13
+
14
+ # prepare query string for API call
15
+ query_builder << "/addresses/{address}"
16
+
17
+ # process optional query parameters
18
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
19
+ "address" => address,
20
+ }
21
+
22
+ # validate and preprocess url
23
+ query_url = APIHelper.clean_url query_builder
24
+
25
+ # prepare headers
26
+ headers = {
27
+ "user-agent" => "APIMATIC 2.0",
28
+ "accept" => "application/json",
29
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
30
+ "network" => network
31
+ }
32
+
33
+ # invoke the API call request to fetch the response
34
+ response = Unirest.get query_url, headers:headers
35
+
36
+ #Error handling using HTTP status codes
37
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
38
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
39
+ end
40
+
41
+ response.body
42
+ end
43
+
44
+ # Returns a collection of addresses for an account.
45
+ # @param [String] id Required parameter: An account id
46
+ # @param [String] network Required parameter: Blockchain network
47
+ # @return mixed response from the API call
48
+ def list id, network
49
+ # the base uri for api requests
50
+ query_builder = Configuration.BASE_URI.dup
51
+
52
+ # prepare query string for API call
53
+ query_builder << "/accounts/{id}/addresses"
54
+
55
+ # process optional query parameters
56
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
57
+ "id" => id,
58
+ }
59
+
60
+ # validate and preprocess url
61
+ query_url = APIHelper.clean_url query_builder
62
+
63
+ # prepare headers
64
+ headers = {
65
+ "user-agent" => "APIMATIC 2.0",
66
+ "accept" => "application/json",
67
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
68
+ "network" => network
69
+ }
70
+
71
+ # invoke the API call request to fetch the response
72
+ response = Unirest.get query_url, headers:headers
73
+
74
+ #Error handling using HTTP status codes
75
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
76
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
77
+ end
78
+
79
+ response.body
80
+ end
81
+
82
+ # Returns details of an address.
83
+ # @param [String] address Required parameter: An address
84
+ # @param [String] network Required parameter: Blockchain network
85
+ # @return mixed response from the API call
86
+ def show address, network
87
+ # the base uri for api requests
88
+ query_builder = Configuration.BASE_URI.dup
89
+
90
+ # prepare query string for API call
91
+ query_builder << "/addresses/{address}/show"
92
+
93
+ # process optional query parameters
94
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
95
+ "address" => address,
96
+ }
97
+
98
+ # validate and preprocess url
99
+ query_url = APIHelper.clean_url query_builder
100
+
101
+ # prepare headers
102
+ headers = {
103
+ "user-agent" => "APIMATIC 2.0",
104
+ "accept" => "application/json",
105
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
106
+ "network" => network
107
+ }
108
+
109
+ # invoke the API call request to fetch the response
110
+ response = Unirest.get query_url, headers:headers
111
+
112
+ #Error handling using HTTP status codes
113
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
114
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
115
+ end
116
+
117
+ response.body
118
+ end
119
+
120
+ # Returns a newly created address.
121
+ # @param [String] account_id Required parameter: An account id
122
+ # @param [String] network Required parameter: Blockchain network
123
+ # @return mixed response from the API call
124
+ def create account_id, network
125
+ # the base uri for api requests
126
+ query_builder = Configuration.BASE_URI.dup
127
+
128
+ # prepare query string for API call
129
+ query_builder << "/addresses/new"
130
+
131
+ # validate and preprocess url
132
+ query_url = APIHelper.clean_url query_builder
133
+
134
+ # prepare headers
135
+ headers = {
136
+ "user-agent" => "APIMATIC 2.0",
137
+ "accept" => "application/json",
138
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
139
+ "network" => network
140
+ }
141
+
142
+ # prepare parameters
143
+ parameters = {
144
+ "account_id" => account_id
145
+ }
146
+
147
+ # invoke the API call request to fetch the response
148
+ response = Unirest.post query_url, headers:headers, parameters:parameters
149
+
150
+ #Error handling using HTTP status codes
151
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
152
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
153
+ end
154
+
155
+ response.body
156
+ end
157
+
158
+ # Returns the deleted address.
159
+ # @param [String] address Required parameter: An address
160
+ # @param [String] network Required parameter: Blockchain network
161
+ # @return mixed response from the API call
162
+ def delete address, network
163
+ # the base uri for api requests
164
+ query_builder = Configuration.BASE_URI.dup
165
+
166
+ # prepare query string for API call
167
+ query_builder << "/addresses/delete"
168
+
169
+ # validate and preprocess url
170
+ query_url = APIHelper.clean_url query_builder
171
+
172
+ # prepare headers
173
+ headers = {
174
+ "user-agent" => "APIMATIC 2.0",
175
+ "accept" => "application/json",
176
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
177
+ "network" => network
178
+ }
179
+
180
+ # prepare parameters
181
+ parameters = {
182
+ "address" => address
183
+ }
184
+
185
+ # invoke the API call request to fetch the response
186
+ response = Unirest.delete query_url, headers:headers, parameters:parameters
187
+
188
+ #Error handling using HTTP status codes
189
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
190
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
191
+ end
192
+
193
+ response.body
194
+ end
195
+
196
+ # Returns a set of transactions for an addresses.
197
+ # @param [String] address Required parameter: An address
198
+ # @param [String] network Required parameter: Blockchain network
199
+ # @param [Numeric] limit Optional parameter: The number of transactions to return, starting with most recent (default=50, max=500)
200
+ # @return mixed response from the API call
201
+ def get_address_transactions address, network, limit: nil
202
+ # the base uri for api requests
203
+ query_builder = Configuration.BASE_URI.dup
204
+
205
+ # prepare query string for API call
206
+ query_builder << "/addresses/{address}/transactions"
207
+
208
+ # process optional query parameters
209
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
210
+ "address" => address,
211
+ }
212
+
213
+ # process optional query parameters
214
+ query_builder = APIHelper.append_url_with_query_parameters query_builder, {
215
+ "limit" => limit,
216
+ }
217
+
218
+ # validate and preprocess url
219
+ query_url = APIHelper.clean_url query_builder
220
+
221
+ # prepare headers
222
+ headers = {
223
+ "user-agent" => "APIMATIC 2.0",
224
+ "accept" => "application/json",
225
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
226
+ "network" => network
227
+ }
228
+
229
+ # invoke the API call request to fetch the response
230
+ response = Unirest.get query_url, headers:headers
231
+
232
+ #Error handling using HTTP status codes
233
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
234
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
235
+ end
236
+
237
+ response.body
238
+ end
239
+
240
+ # Returns a collection of unspent outputs for an address. These outputs can be used as inputs for a new transaction.
241
+ # @param [String] address Required parameter: An address
242
+ # @param [String] network Required parameter: Blockchain network
243
+ # @return mixed response from the API call
244
+ def get_address_unspent_outputs address, network
245
+ # the base uri for api requests
246
+ query_builder = Configuration.BASE_URI.dup
247
+
248
+ # prepare query string for API call
249
+ query_builder << "/addresses/{address}/unspents"
250
+
251
+ # process optional query parameters
252
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
253
+ "address" => address,
254
+ }
255
+
256
+ # validate and preprocess url
257
+ query_url = APIHelper.clean_url query_builder
258
+
259
+ # prepare headers
260
+ headers = {
261
+ "user-agent" => "APIMATIC 2.0",
262
+ "accept" => "application/json",
263
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
264
+ "network" => network
265
+ }
266
+
267
+ # invoke the API call request to fetch the response
268
+ response = Unirest.get query_url, headers:headers
269
+
270
+ #Error handling using HTTP status codes
271
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
272
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
273
+ end
274
+
275
+ response.body
276
+ end
277
+
278
+ end
279
+ end
@@ -0,0 +1,103 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class APIKeyController
5
+
6
+ # Returns a newly created API key.
7
+ # @return mixed response from the API call
8
+ def create
9
+ # the base uri for api requests
10
+ query_builder = Configuration.BASE_URI.dup
11
+
12
+ # prepare query string for API call
13
+ query_builder << "/clients/new"
14
+
15
+ # validate and preprocess url
16
+ query_url = APIHelper.clean_url query_builder
17
+
18
+ # prepare headers
19
+ headers = {
20
+ "user-agent" => "APIMATIC 2.0",
21
+ "accept" => "application/json",
22
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
23
+ }
24
+
25
+ # invoke the API call request to fetch the response
26
+ response = Unirest.post query_url, headers:headers
27
+
28
+ #Error handling using HTTP status codes
29
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
30
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
31
+ end
32
+
33
+ response.body
34
+ end
35
+
36
+ # Returns a collection of API keys for the authorized user.
37
+ # @return mixed response from the API call
38
+ def list
39
+ # the base uri for api requests
40
+ query_builder = Configuration.BASE_URI.dup
41
+
42
+ # prepare query string for API call
43
+ query_builder << "/clients/list"
44
+
45
+ # validate and preprocess url
46
+ query_url = APIHelper.clean_url query_builder
47
+
48
+ # prepare headers
49
+ headers = {
50
+ "user-agent" => "APIMATIC 2.0",
51
+ "accept" => "application/json",
52
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
53
+ }
54
+
55
+ # invoke the API call request to fetch the response
56
+ response = Unirest.get query_url, headers:headers
57
+
58
+ #Error handling using HTTP status codes
59
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
60
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
61
+ end
62
+
63
+ response.body
64
+ end
65
+
66
+ # Returns the deleted API key id.
67
+ # @param [String] id Required parameter: An API key id
68
+ # @return mixed response from the API call
69
+ def delete id
70
+ # the base uri for api requests
71
+ query_builder = Configuration.BASE_URI.dup
72
+
73
+ # prepare query string for API call
74
+ query_builder << "/clients/delete"
75
+
76
+ # validate and preprocess url
77
+ query_url = APIHelper.clean_url query_builder
78
+
79
+ # prepare headers
80
+ headers = {
81
+ "user-agent" => "APIMATIC 2.0",
82
+ "accept" => "application/json",
83
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
84
+ }
85
+
86
+ # prepare parameters
87
+ parameters = {
88
+ "id" => id
89
+ }
90
+
91
+ # invoke the API call request to fetch the response
92
+ response = Unirest.delete query_url, headers:headers, parameters:parameters
93
+
94
+ #Error handling using HTTP status codes
95
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
96
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
97
+ end
98
+
99
+ response.body
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,85 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class AuthorizationController
5
+
6
+ # TODO: type endpoint description here
7
+ # @param [String] client_id Required parameter: TODO: type description here
8
+ # @param [String] client_secret Required parameter: TODO: type description here
9
+ # @return mixed response from the API call
10
+ def get_access_token_by_client_credential client_id, client_secret
11
+ # the base uri for api requests
12
+ query_builder = Configuration.BASE_URI.dup
13
+
14
+ # prepare query string for API call
15
+ query_builder << "/oauth2/token"
16
+
17
+ # validate and preprocess url
18
+ query_url = APIHelper.clean_url query_builder
19
+
20
+ # prepare headers
21
+ headers = {
22
+ "user-agent" => "APIMATIC 2.0",
23
+ "accept" => "application/json"
24
+ }
25
+
26
+ # prepare parameters
27
+ parameters = {
28
+ "client_id" => client_id,
29
+ "client_secret" => client_secret,
30
+ "grant_type" => "client_credentials"
31
+ }
32
+
33
+ # invoke the API call request to fetch the response
34
+ response = Unirest.post query_url, headers:headers, parameters:parameters
35
+
36
+ #Error handling using HTTP status codes
37
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
38
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
39
+ end
40
+
41
+ response.body
42
+ end
43
+
44
+ # TODO: type endpoint description here
45
+ # @param [String] client_id Required parameter: TODO: type description here
46
+ # @param [String] client_secret Required parameter: TODO: type description here
47
+ # @param [String] refresh_token Required parameter: TODO: type description here
48
+ # @return mixed response from the API call
49
+ def get_access_token_by_refresh_token client_id, client_secret, refresh_token
50
+ # the base uri for api requests
51
+ query_builder = Configuration.BASE_URI.dup
52
+
53
+ # prepare query string for API call
54
+ query_builder << "/oauth2/token"
55
+
56
+ # validate and preprocess url
57
+ query_url = APIHelper.clean_url query_builder
58
+
59
+ # prepare headers
60
+ headers = {
61
+ "user-agent" => "APIMATIC 2.0",
62
+ "accept" => "application/json"
63
+ }
64
+
65
+ # prepare parameters
66
+ parameters = {
67
+ "client_id" => client_id,
68
+ "client_secret" => client_secret,
69
+ "grant_type" => "refresh_token",
70
+ "refresh_token" => refresh_token
71
+ }
72
+
73
+ # invoke the API call request to fetch the response
74
+ response = Unirest.post query_url, headers:headers, parameters:parameters
75
+
76
+ #Error handling using HTTP status codes
77
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
78
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
79
+ end
80
+
81
+ response.body
82
+ end
83
+
84
+ end
85
+ end
@@ -0,0 +1,45 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class BlockController
5
+
6
+ # Returns details about a block, including all transaction hashes.
7
+ # @param [String] block Required parameter: Hash, Height, or Latest
8
+ # @param [String] network Required parameter: Blockchain network
9
+ # @return mixed response from the API call
10
+ def get_block block, network
11
+ # the base uri for api requests
12
+ query_builder = Configuration.BASE_URI.dup
13
+
14
+ # prepare query string for API call
15
+ query_builder << "/blocks/{block}"
16
+
17
+ # process optional query parameters
18
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
19
+ "block" => block,
20
+ }
21
+
22
+ # validate and preprocess url
23
+ query_url = APIHelper.clean_url query_builder
24
+
25
+ # prepare headers
26
+ headers = {
27
+ "user-agent" => "APIMATIC 2.0",
28
+ "accept" => "application/json",
29
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
30
+ "network" => network
31
+ }
32
+
33
+ # invoke the API call request to fetch the response
34
+ response = Unirest.get query_url, headers:headers
35
+
36
+ #Error handling using HTTP status codes
37
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
38
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
39
+ end
40
+
41
+ response.body
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,113 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class NodeController
5
+
6
+ # Returns a collection of nodes for the authorized user.
7
+ # @param [String] network Required parameter: Blockchain network
8
+ # @return mixed response from the API call
9
+ def list network
10
+ # the base uri for api requests
11
+ query_builder = Configuration.BASE_URI.dup
12
+
13
+ # prepare query string for API call
14
+ query_builder << "/nodes/list"
15
+
16
+ # validate and preprocess url
17
+ query_url = APIHelper.clean_url query_builder
18
+
19
+ # prepare headers
20
+ headers = {
21
+ "user-agent" => "APIMATIC 2.0",
22
+ "accept" => "application/json",
23
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
24
+ "network" => network
25
+ }
26
+
27
+ # invoke the API call request to fetch the response
28
+ response = Unirest.get query_url, headers:headers
29
+
30
+ #Error handling using HTTP status codes
31
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
32
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
33
+ end
34
+
35
+ response.body
36
+ end
37
+
38
+ # Returns a newly registered node.
39
+ # @param [String] network Required parameter: Blockchain network
40
+ # @param [mixed] node Required parameter: A node object
41
+ # @return mixed response from the API call
42
+ def register node, network
43
+ # the base uri for api requests
44
+ query_builder = Configuration.BASE_URI.dup
45
+
46
+ # prepare query string for API call
47
+ query_builder << "/nodes/new"
48
+
49
+ # validate and preprocess url
50
+ query_url = APIHelper.clean_url query_builder
51
+
52
+ # prepare headers
53
+ headers = {
54
+ "user-agent" => "APIMATIC 2.0",
55
+ "accept" => "application/json",
56
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
57
+ "network" => network
58
+ }
59
+
60
+ # prepare parameters
61
+ parameters = {
62
+ "node" => node
63
+ }
64
+
65
+ # invoke the API call request to fetch the response
66
+ response = Unirest.post query_url, headers:headers, parameters:parameters
67
+
68
+ #Error handling using HTTP status codes
69
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
70
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
71
+ end
72
+
73
+ response.body
74
+ end
75
+
76
+ # Returns the deleted node id.
77
+ # @param [String] id Required parameter: A node id
78
+ # @return mixed response from the API call
79
+ def delete id
80
+ # the base uri for api requests
81
+ query_builder = Configuration.BASE_URI.dup
82
+
83
+ # prepare query string for API call
84
+ query_builder << "/nodes/delete"
85
+
86
+ # validate and preprocess url
87
+ query_url = APIHelper.clean_url query_builder
88
+
89
+ # prepare headers
90
+ headers = {
91
+ "user-agent" => "APIMATIC 2.0",
92
+ "accept" => "application/json",
93
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token)
94
+ }
95
+
96
+ # prepare parameters
97
+ parameters = {
98
+ "id" => id
99
+ }
100
+
101
+ # invoke the API call request to fetch the response
102
+ response = Unirest.delete query_url, headers:headers, parameters:parameters
103
+
104
+ #Error handling using HTTP status codes
105
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
106
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
107
+ end
108
+
109
+ response.body
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,159 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+
3
+ module ScaleChain
4
+ class TransactionController
5
+
6
+ # Returns details about a transaction, including inputs and outputs.
7
+ # @param [String] hash Required parameter: A transaction hash
8
+ # @param [String] network Required parameter: Blockchain network
9
+ # @return mixed response from the API call
10
+ def get_transaction hash, network
11
+ # the base uri for api requests
12
+ query_builder = Configuration.BASE_URI.dup
13
+
14
+ # prepare query string for API call
15
+ query_builder << "/transactions/{hash}"
16
+
17
+ # process optional query parameters
18
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
19
+ "hash" => hash,
20
+ }
21
+
22
+ # validate and preprocess url
23
+ query_url = APIHelper.clean_url query_builder
24
+
25
+ # prepare headers
26
+ headers = {
27
+ "user-agent" => "APIMATIC 2.0",
28
+ "accept" => "application/json",
29
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
30
+ "network" => network
31
+ }
32
+
33
+ # invoke the API call request to fetch the response
34
+ response = Unirest.get query_url, headers:headers
35
+
36
+ #Error handling using HTTP status codes
37
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
38
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
39
+ end
40
+
41
+ response.body
42
+ end
43
+
44
+ # Returns the raw transaction hex data for a given transaction hash.
45
+ # @param [String] hash Required parameter: A transaction hash
46
+ # @param [String] network Required parameter: Blockchain network
47
+ # @return mixed response from the API call
48
+ def get_raw_transaction_hex hash, network
49
+ # the base uri for api requests
50
+ query_builder = Configuration.BASE_URI.dup
51
+
52
+ # prepare query string for API call
53
+ query_builder << "/transactions/{hash}/hex"
54
+
55
+ # process optional query parameters
56
+ query_builder = APIHelper.append_url_with_template_parameters query_builder, {
57
+ "hash" => hash,
58
+ }
59
+
60
+ # validate and preprocess url
61
+ query_url = APIHelper.clean_url query_builder
62
+
63
+ # prepare headers
64
+ headers = {
65
+ "user-agent" => "APIMATIC 2.0",
66
+ "accept" => "application/json",
67
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
68
+ "network" => network
69
+ }
70
+
71
+ # invoke the API call request to fetch the response
72
+ response = Unirest.get query_url, headers:headers
73
+
74
+ #Error handling using HTTP status codes
75
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
76
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
77
+ end
78
+
79
+ response.body
80
+ end
81
+
82
+ # Returns a signed transaction in hex.
83
+ # @param [String] network Required parameter: Blockchain network
84
+ # @param [String] raw_tx_hex Required parameter: A raw transaction in hex
85
+ # @return mixed response from the API call
86
+ def sign_raw_transaction raw_tx_hex, network
87
+ # the base uri for api requests
88
+ query_builder = Configuration.BASE_URI.dup
89
+
90
+ # prepare query string for API call
91
+ query_builder << "/transactions/sign"
92
+
93
+ # validate and preprocess url
94
+ query_url = APIHelper.clean_url query_builder
95
+
96
+ # prepare headers
97
+ headers = {
98
+ "user-agent" => "APIMATIC 2.0",
99
+ "accept" => "application/json",
100
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
101
+ "network" => network
102
+ }
103
+
104
+ # prepare parameters
105
+ parameters = {
106
+ "raw_tx_hex" => raw_tx_hex
107
+ }
108
+
109
+ # invoke the API call request to fetch the response
110
+ response = Unirest.post query_url, headers:headers, parameters:parameters
111
+
112
+ #Error handling using HTTP status codes
113
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
114
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
115
+ end
116
+
117
+ response.body
118
+ end
119
+
120
+ # Accepts a raw signed transaction in hex format and submits to the blockchain network and returns the transaction hash in hex.
121
+ # @param [String] network Required parameter: Blockchain network
122
+ # @param [String] signed_hex Required parameter: A signed transaction in hex format
123
+ # @return mixed response from the API call
124
+ def send_signed_transaction signed_hex, network
125
+ # the base uri for api requests
126
+ query_builder = Configuration.BASE_URI.dup
127
+
128
+ # prepare query string for API call
129
+ query_builder << "/transactions/send"
130
+
131
+ # validate and preprocess url
132
+ query_url = APIHelper.clean_url query_builder
133
+
134
+ # prepare headers
135
+ headers = {
136
+ "user-agent" => "APIMATIC 2.0",
137
+ "accept" => "application/json",
138
+ "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token),
139
+ "network" => network
140
+ }
141
+
142
+ # prepare parameters
143
+ parameters = {
144
+ "signed_hex" => signed_hex
145
+ }
146
+
147
+ # invoke the API call request to fetch the response
148
+ response = Unirest.post query_url, headers:headers, parameters:parameters
149
+
150
+ #Error handling using HTTP status codes
151
+ if !(response.code.between?(200,206)) # [200,206] = HTTP OK
152
+ raise APIException.new "HTTP Response Not OK", response.code, response.raw_body
153
+ end
154
+
155
+ response.body
156
+ end
157
+
158
+ end
159
+ end
data/lib/scalechain.rb ADDED
@@ -0,0 +1,20 @@
1
+ # This file was automatically generated by APIMATIC BETA v2.0 on 02/26/2016
2
+ require 'openssl'
3
+ require 'json'
4
+ require 'unirest'
5
+
6
+ # APIMATIC Helper Files
7
+ require 'scalechain/api_helper.rb'
8
+ require 'scalechain/api_exception.rb'
9
+ require 'scalechain/configuration.rb'
10
+
11
+ # Controllers
12
+ require 'scalechain/controllers/authorization_controller.rb'
13
+ require 'scalechain/controllers/api_key_controller.rb'
14
+ require 'scalechain/controllers/account_controller.rb'
15
+ require 'scalechain/controllers/address_controller.rb'
16
+ require 'scalechain/controllers/node_controller.rb'
17
+ require 'scalechain/controllers/block_controller.rb'
18
+ require 'scalechain/controllers/transaction_controller.rb'
19
+
20
+ # Models
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scalechain
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ScaleChain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unirest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.2
27
+ description: The ScaleChain SDK for Ruby
28
+ email: developer@scalechain.io
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/scalechain.rb
35
+ - lib/scalechain/api_exception.rb
36
+ - lib/scalechain/api_helper.rb
37
+ - lib/scalechain/configuration.rb
38
+ - lib/scalechain/controllers/account_controller.rb
39
+ - lib/scalechain/controllers/address_controller.rb
40
+ - lib/scalechain/controllers/api_key_controller.rb
41
+ - lib/scalechain/controllers/authorization_controller.rb
42
+ - lib/scalechain/controllers/block_controller.rb
43
+ - lib/scalechain/controllers/node_controller.rb
44
+ - lib/scalechain/controllers/transaction_controller.rb
45
+ homepage: https://scalechain.io
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.6
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: The ScaleChain SDK for Ruby
68
+ test_files: []