Class: ScaleChain::AddressController
- Inherits:
-
Object
- Object
- ScaleChain::AddressController
- Defined in:
- lib/scalechain/controllers/address_controller.rb
Instance Method Summary collapse
-
#create(account_id, network) ⇒ Object
Returns a newly created address.
-
#delete(address, network) ⇒ Object
Returns the deleted address.
-
#get_address(address, network) ⇒ Object
Returns basic balance details for an addresses.
-
#get_address_transactions(address, network, limit: nil) ⇒ Object
Returns a set of transactions for an addresses.
-
#get_address_unspent_outputs(address, network) ⇒ Object
Returns a collection of unspent outputs for an address.
-
#list(id, network) ⇒ Object
Returns a collection of addresses for an account.
-
#show(address, network) ⇒ Object
Returns details of an address.
Instance Method Details
#create(account_id, network) ⇒ Object
Returns a newly created address.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/scalechain/controllers/address_controller.rb', line 124 def create account_id, network # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/addresses/new" # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # prepare parameters parameters = { "account_id" => account_id } # invoke the API call request to fetch the response response = Unirest.post query_url, headers:headers, parameters:parameters #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |
#delete(address, network) ⇒ Object
Returns the deleted address.
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/scalechain/controllers/address_controller.rb', line 162 def delete address, network # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/addresses/delete" # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # prepare parameters parameters = { "address" => address } # invoke the API call request to fetch the response response = Unirest.delete query_url, headers:headers, parameters:parameters #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |
#get_address(address, network) ⇒ Object
Returns basic balance details for an addresses.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/scalechain/controllers/address_controller.rb', line 10 def get_address address, network # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/addresses/{address}" # process optional query parameters query_builder = APIHelper.append_url_with_template_parameters query_builder, { "address" => address, } # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # invoke the API call request to fetch the response response = Unirest.get query_url, headers:headers #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |
#get_address_transactions(address, network, limit: nil) ⇒ Object
Returns a set of transactions for an addresses.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/scalechain/controllers/address_controller.rb', line 201 def get_address_transactions address, network, limit: nil # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/addresses/{address}/transactions" # process optional query parameters query_builder = APIHelper.append_url_with_template_parameters query_builder, { "address" => address, } # process optional query parameters query_builder = APIHelper.append_url_with_query_parameters query_builder, { "limit" => limit, } # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # invoke the API call request to fetch the response response = Unirest.get query_url, headers:headers #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |
#get_address_unspent_outputs(address, network) ⇒ Object
Returns a collection of unspent outputs for an address. These outputs can be used as inputs for a new transaction.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/scalechain/controllers/address_controller.rb', line 244 def get_address_unspent_outputs address, network # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/addresses/{address}/unspents" # process optional query parameters query_builder = APIHelper.append_url_with_template_parameters query_builder, { "address" => address, } # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # invoke the API call request to fetch the response response = Unirest.get query_url, headers:headers #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |
#list(id, network) ⇒ Object
Returns a collection of addresses for an account.
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 75 76 77 78 79 80 |
# File 'lib/scalechain/controllers/address_controller.rb', line 48 def list id, network # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/accounts/{id}/addresses" # process optional query parameters query_builder = APIHelper.append_url_with_template_parameters query_builder, { "id" => id, } # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # invoke the API call request to fetch the response response = Unirest.get query_url, headers:headers #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |
#show(address, network) ⇒ Object
Returns details of an address.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/scalechain/controllers/address_controller.rb', line 86 def show address, network # the base uri for api requests query_builder = Configuration.BASE_URI.dup # prepare query string for API call query_builder << "/addresses/{address}/show" # process optional query parameters query_builder = APIHelper.append_url_with_template_parameters query_builder, { "address" => address, } # validate and preprocess url query_url = APIHelper.clean_url query_builder # prepare headers headers = { "user-agent" => "APIMATIC 2.0", "accept" => "application/json", "Authorization" => "Bearer %s" % (Configuration.o_auth_access_token), "network" => network } # invoke the API call request to fetch the response response = Unirest.get query_url, headers:headers #Error handling using HTTP status codes if !(response.code.between?(200,206)) # [200,206] = HTTP OK raise APIException.new "HTTP Response Not OK", response.code, response.raw_body end response.body end |