Class: Quizlet::Client
- Inherits:
-
Object
show all
- Includes:
- Sets
- Defined in:
- lib/quizlet/client.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Sets
#add_set, #add_term_to_set_by_id, #delete_set_by_id, #delete_term_in_set_by_id, #edit_set_by_id, #edit_term_in_set_by_id, #get_favorite_sets_by_user_id, #get_set_by_id, #get_set_password_by_id, #get_set_terms_by_id, #get_sets, #get_sets_by_class_id, #get_sets_by_user_id
Constructor Details
#initialize(opts) ⇒ Client
Returns a new instance of Client.
18
19
20
21
|
# File 'lib/quizlet/client.rb', line 18
def initialize(opts)
@access_token = opts[:access_token]
@client_id = opts[:client_id]
end
|
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
16
17
18
|
# File 'lib/quizlet/client.rb', line 16
def access_token
@access_token
end
|
#client_id ⇒ Object
Returns the value of attribute client_id.
16
17
18
|
# File 'lib/quizlet/client.rb', line 16
def client_id
@client_id
end
|
Instance Method Details
#connection ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/quizlet/client.rb', line 49
def connection
@connection ||= Faraday.new('https://api.quizlet.com/2.0', CONNECTION_OPTIONS) do |conn|
conn.request :url_encoded
conn.authorization :Bearer, access_token
conn.adapter Faraday.default_adapter
end
end
|
#delete(endpoint, params) ⇒ Object
35
36
37
|
# File 'lib/quizlet/client.rb', line 35
def delete(endpoint, params)
request(:delete, endpoint, params)
end
|
#get(endpoint, params) ⇒ Object
23
24
25
|
# File 'lib/quizlet/client.rb', line 23
def get(endpoint, params)
request(:get, endpoint, params)
end
|
#post(endpoint, params) ⇒ Object
27
28
29
|
# File 'lib/quizlet/client.rb', line 27
def post(endpoint, params)
request(:post, endpoint, params)
end
|
#put(endpoint, params) ⇒ Object
31
32
33
|
# File 'lib/quizlet/client.rb', line 31
def put(endpoint, params)
request(:put, endpoint, params)
end
|
#request(action, endpoint, params) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/quizlet/client.rb', line 39
def request(action, endpoint, params)
res = connection.send(action, endpoint, params).env
if res[:body] && res[:body] != ''
JSON.parse res[:body]
else
{status: res[:status]}
end
end
|