Class: Inkdit::Client

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

Overview

a client that can issue authenticated HTTP requests to Inkdit’s API.

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

token is a Hash containing the details of the access token returned by Inkdit.get_token. The keys access_token, refresh_token, and expires_at are required.



6
7
8
9
# File 'lib/inkdit/client.rb', line 6

def initialize(token)
  # AccessToken#from_hash modifies the hash it's passed.
  @access_token = OAuth2::AccessToken.from_hash(oauth_client, token.clone)
end

Instance Method Details

#delete(path, params) ⇒ OAuth2::Response

issue an HTTP DELETE.

Returns:

  • (OAuth2::Response)


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

def delete(path, params)
  request(:delete, path, {})
end

#get(path) ⇒ OAuth2::Response

issue an HTTP GET.

Returns:

  • (OAuth2::Response)


21
22
23
# File 'lib/inkdit/client.rb', line 21

def get(path)
  request(:get, path, {})
end

#get_entityEntity

Returns the entity that this access token belongs to.

Returns:

  • (Entity)

    the entity that this access token belongs to



12
13
14
15
16
17
# File 'lib/inkdit/client.rb', line 12

def get_entity
  response = get '/v1/'

  entity = response.parsed["entities"].first
  Entity.new(self, entity)
end

#post(path, params) ⇒ OAuth2::Response

issue an HTTP POST.

Returns:

  • (OAuth2::Response)


27
28
29
# File 'lib/inkdit/client.rb', line 27

def post(path, params)
  request(:post, path, params)
end

#put(path, params) ⇒ OAuth2::Response

issue an HTTP PUT.

Returns:

  • (OAuth2::Response)


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

def put(path, params)
  request(:put, path, params)
end