Class: Passfort::Http

Inherits:
Object
  • Object
show all
Defined in:
lib/passfort/http.rb

Constant Summary collapse

DOMAIN =
"https://api.passfort.com"
ROOT_PATH =
"/4.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, excon_opts = {}) ⇒ Http

Returns a new instance of Http.



14
15
16
17
18
# File 'lib/passfort/http.rb', line 14

def initialize(api_key, excon_opts = {})
  @api_key = api_key
  uri = excon_opts[:domain] || DOMAIN
  @connection = Excon.new(uri, excon_opts.except(:domain))
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



12
13
14
# File 'lib/passfort/http.rb', line 12

def api_key
  @api_key
end

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/passfort/http.rb', line 12

def connection
  @connection
end

Instance Method Details

#get(path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/passfort/http.rb', line 20

def get(path)
  execute(
    -> {
      @connection.get(
        path: ROOT_PATH + path,
        headers: { apikey: @api_key },
      )
    },
    :get,
    path: path,
  )
end

#post(path, body:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/passfort/http.rb', line 33

def post(path, body:)
  execute(
    -> {
      @connection.post(
        path: ROOT_PATH + path,
        body: body.to_json,
        headers: { apikey: @api_key, "Content-Type" => "application/json" },
      )
    },
    :post,
    path: path,
    body: body,
  )
end