Class: MasonHubAPI::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url_slug:, base_path: "v1", bearer_token:, adapter: Faraday.default_adapter, sandbox: false) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
# File 'lib/mason_hub_api/client.rb', line 7

def initialize(url_slug:, base_path: "v1", bearer_token:, adapter: Faraday.default_adapter, sandbox: false)
  @url_slug = url_slug
  @base_path = base_path
  @bearer_token = bearer_token
  @adapter = adapter
  @sandbox = sandbox
end

Instance Attribute Details

#adapterObject (readonly)

Returns the value of attribute adapter.



5
6
7
# File 'lib/mason_hub_api/client.rb', line 5

def adapter
  @adapter
end

#base_pathObject (readonly)

Returns the value of attribute base_path.



5
6
7
# File 'lib/mason_hub_api/client.rb', line 5

def base_path
  @base_path
end

#bearer_tokenObject (readonly)

Returns the value of attribute bearer_token.



5
6
7
# File 'lib/mason_hub_api/client.rb', line 5

def bearer_token
  @bearer_token
end

#sandboxObject (readonly)

Returns the value of attribute sandbox.



5
6
7
# File 'lib/mason_hub_api/client.rb', line 5

def sandbox
  @sandbox
end

#url_slugObject (readonly)

Returns the value of attribute url_slug.



5
6
7
# File 'lib/mason_hub_api/client.rb', line 5

def url_slug
  @url_slug
end

Instance Method Details

#callbackObject



26
27
28
# File 'lib/mason_hub_api/client.rb', line 26

def callback
  @callbacks ||= CallbackResource.new(self)
end

#connectionObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/mason_hub_api/client.rb', line 15

def connection
  @connection ||= Faraday.new do |conn|
    conn.url_prefix = url_prefix
    conn.headers['Authorization'] = "Bearer #{bearer_token}"
    conn.headers['Content-Type'] = "application/json"
    conn.request :json
    conn.response :json, content_type: "application/json"
    conn.adapter adapter
  end
end

#returnObject



30
31
32
# File 'lib/mason_hub_api/client.rb', line 30

def return
  @returns ||= ReturnResource.new(self)
end