Class: Etna::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/etna/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#routesObject (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



47
48
49
# File 'lib/etna/client.rb', line 47

def delete(endpoint, params = {}, &block)
  body_request(Net::HTTP::Delete, endpoint, params, &block)
end

#get(endpoint, params = {}, &block) ⇒ Object



35
36
37
# File 'lib/etna/client.rb', line 35

def get(endpoint, params = {}, &block)
  query_request(Net::HTTP::Get, endpoint, params, &block)
end

#head(endpoint, params = {}, &block) ⇒ Object



39
40
41
# File 'lib/etna/client.rb', line 39

def head(endpoint, params = {}, &block)
  query_request(Net::HTTP::Head, endpoint, params, &block)
end

#multipart_post(endpoint, content, &block) ⇒ Object



24
25
26
27
28
29
# File 'lib/etna/client.rb', line 24

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



43
44
45
# File 'lib/etna/client.rb', line 43

def options(endpoint, params = {}, &block)
  query_request(Net::HTTP::Options, endpoint, params, &block)
end

#post(endpoint, params = {}, &block) ⇒ Object



31
32
33
# File 'lib/etna/client.rb', line 31

def post(endpoint, params = {}, &block)
  body_request(Net::HTTP::Post, endpoint, params, &block)
end

#route_path(route, params) ⇒ Object



20
21
22
# File 'lib/etna/client.rb', line 20

def route_path(route, params)
  Etna::Route.path(route[:route], params)
end