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, persistent: true, ignore_ssl: false) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/etna/client.rb', line 8

def initialize(host, token, routes_available: true, persistent: true, ignore_ssl: false)
  @host = host.sub(%r!/$!, '')
  @token = token
  @persistent = persistent
  @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.



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

def routes
  @routes
end

Instance Method Details

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



45
46
47
# File 'lib/etna/client.rb', line 45

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

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



37
38
39
# File 'lib/etna/client.rb', line 37

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

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



26
27
28
29
30
31
# File 'lib/etna/client.rb', line 26

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



41
42
43
# File 'lib/etna/client.rb', line 41

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

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



33
34
35
# File 'lib/etna/client.rb', line 33

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

#route_path(route, params) ⇒ Object



22
23
24
# File 'lib/etna/client.rb', line 22

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