Class: MOCO::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/moco/connection.rb

Overview

Handles HTTP communication with the MOCO API Responsible for building API requests and converting responses to entity objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, subdomain, api_key, debug: false) ⇒ Connection

Returns a new instance of Connection.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/moco/connection.rb', line 12

def initialize(client, subdomain, api_key, debug: false)
  @client = client
  @subdomain = subdomain
  @api_key = api_key
  @debug = debug
  @conn = Faraday.new do |f|
    f.request :json
    f.response :json
    f.request :authorization, "Token", "token=#{@api_key}"
    f.url_prefix = "https://#{@subdomain}.mocoapp.com/api/v1"
  end
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



10
11
12
# File 'lib/moco/connection.rb', line 10

def api_key
  @api_key
end

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/moco/connection.rb', line 10

def client
  @client
end

#debugObject (readonly)

Returns the value of attribute debug.



10
11
12
# File 'lib/moco/connection.rb', line 10

def debug
  @debug
end

#subdomainObject (readonly)

Returns the value of attribute subdomain.



10
11
12
# File 'lib/moco/connection.rb', line 10

def subdomain
  @subdomain
end