Class: Credly::Client

Inherits:
Object
  • Object
show all
Includes:
Connection, Requierable
Defined in:
lib/credly/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Requierable

#require_at_least_one_file, #require_present

Methods included from Connection

#connection, #new_connection, #request

Constructor Details

#initialize(options = Hash.new) ⇒ Client

Returns a new instance of Client.



8
9
10
# File 'lib/credly/client.rb', line 8

def initialize(options = Hash.new)
  @options = OpenStruct.new(Credly.options.merge(options))
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#apiObject



12
13
14
# File 'lib/credly/client.rb', line 12

def api
  Api.new(self)
end

#authenticate(username, password) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/credly/client.rb', line 16

def authenticate(username, password)
  connection = new_connection
  connection.basic_auth(username, password)
  resp = connection.post(versioned_path('authenticate'))
  resp = OpenStruct.new(MultiJson.load(resp.body))
  if resp.status_code == 200
    options.auth_token = resp.data['token']
  else
    resp
  end
end

#base_urlObject



44
45
46
# File 'lib/credly/client.rb', line 44

def base_url
  options.base_endpoint
end

#delete(path, params = Hash.new, headers = Hash.new) ⇒ Object



40
41
42
# File 'lib/credly/client.rb', line 40

def delete(path, params = Hash.new, headers = Hash.new)
  super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
end

#get(path, params = Hash.new, headers = Hash.new) ⇒ Object



28
29
30
# File 'lib/credly/client.rb', line 28

def get(path, params = Hash.new, headers = Hash.new)
  super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
end

#post(path, params = Hash.new, headers = Hash.new) ⇒ Object



32
33
34
# File 'lib/credly/client.rb', line 32

def post(path, params = Hash.new, headers = Hash.new)
  super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
end

#put(path, params = Hash.new, headers = Hash.new) ⇒ Object



36
37
38
# File 'lib/credly/client.rb', line 36

def put(path, params = Hash.new, headers = Hash.new)
  super(versioned_path(path), {:access_token => options.auth_token}.merge(params), headers)
end