Class: Etna::Client
- Inherits:
-
Object
- Object
- Etna::Client
- Defined in:
- lib/etna/client.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #delete(endpoint, params = {}, &block) ⇒ Object
- #get(endpoint, params = {}, &block) ⇒ Object
- #head(endpoint, params = {}, &block) ⇒ Object
-
#initialize(host, token, routes_available: true, ignore_ssl: false) ⇒ Client
constructor
A new instance of Client.
- #multipart_post(endpoint, content, &block) ⇒ Object
- #options(endpoint, params = {}, &block) ⇒ Object
- #post(endpoint, params = {}, &block) ⇒ Object
- #route_path(route, params) ⇒ Object
- #signed_route_path(route, params) ⇒ Object
Constructor Details
#initialize(host, token, routes_available: true, ignore_ssl: false) ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/etna/client.rb', line 7 def initialize(host, token, routes_available: true, ignore_ssl: false) @host = host.sub(%r!/$!, '') @token = token @ignore_ssl = ignore_ssl if routes_available set_routes define_route_helpers end end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
18 19 20 |
# File 'lib/etna/client.rb', line 18 def routes @routes end |
Instance Method Details
#delete(endpoint, params = {}, &block) ⇒ Object
70 71 72 |
# File 'lib/etna/client.rb', line 70 def delete(endpoint, params = {}, &block) body_request(Net::HTTP::Delete, endpoint, params, &block) end |
#get(endpoint, params = {}, &block) ⇒ Object
58 59 60 |
# File 'lib/etna/client.rb', line 58 def get(endpoint, params = {}, &block) query_request(Net::HTTP::Get, endpoint, params, &block) end |
#head(endpoint, params = {}, &block) ⇒ Object
62 63 64 |
# File 'lib/etna/client.rb', line 62 def head(endpoint, params = {}, &block) query_request(Net::HTTP::Head, endpoint, params, &block) end |
#multipart_post(endpoint, content, &block) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/etna/client.rb', line 47 def multipart_post(endpoint, content, &block) uri = request_uri(endpoint) multipart = Net::HTTP::Post::Multipart.new uri.request_uri, content multipart.add_field('Authorization', "Etna #{@token}") request(uri, multipart, &block) end |
#options(endpoint, params = {}, &block) ⇒ Object
66 67 68 |
# File 'lib/etna/client.rb', line 66 def (endpoint, params = {}, &block) query_request(Net::HTTP::Options, endpoint, params, &block) end |
#post(endpoint, params = {}, &block) ⇒ Object
54 55 56 |
# File 'lib/etna/client.rb', line 54 def post(endpoint, params = {}, &block) body_request(Net::HTTP::Post, endpoint, params, &block) end |
#route_path(route, params) ⇒ Object
43 44 45 |
# File 'lib/etna/client.rb', line 43 def route_path(route, params) Etna::Route.path(route[:route], params) end |
#signed_route_path(route, params) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/etna/client.rb', line 20 def signed_route_path(route, params) path = route_path(route,params) signatory = params.delete(:signatory) return path unless signatory hmac = Etna::Hmac.new( signatory, method: route[:method], host: URI(@host).host, path: path, expiration: (DateTime.now + 10).iso8601, id: signatory.id, nonce: SecureRandom.hex, headers: params.except(*route[:params].map(&:to_sym)) ) url_params = hmac.url_params(route[:method] == 'GET') return url_params[:path] + '?' + url_params[:query] end |