quizlet-ruby 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/LICENSE.md +20 -0
- data/README.md +4 -0
- data/lib/quizlet.rb +35 -0
- data/lib/quizlet/client.rb +58 -0
- data/lib/quizlet/sets.rb +57 -0
- data/quizlet-ruby.gemspec +18 -0
- metadata +84 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
example_run.rb
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Matthew Taro DuVall
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/lib/quizlet.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
module Quizlet
|
2
|
+
class << self
|
3
|
+
# Not the place to put this...duplicated
|
4
|
+
def configure(opts)
|
5
|
+
@access_token = opts[:access_token]
|
6
|
+
@client_id = opts[:client_id]
|
7
|
+
end
|
8
|
+
|
9
|
+
def client
|
10
|
+
@client = Quizlet::Client.new({access_token: @access_token, client_id: @client_id})
|
11
|
+
@client
|
12
|
+
end
|
13
|
+
|
14
|
+
def respond_to_missing?(method, include_all=false)
|
15
|
+
client.respond_to?(method, include_all)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Delegate all calls to the client instance, top level module for convenience
|
19
|
+
def respond_to?(method, include_all=false)
|
20
|
+
client.respond_to?(method, include_all) || super
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def method_missing(method, *args, &block)
|
26
|
+
if client.respond_to?(method)
|
27
|
+
return client.send(method, *args, &block)
|
28
|
+
else
|
29
|
+
return super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'quizlet/client'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'quizlet/sets'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Quizlet
|
6
|
+
CONNECTION_OPTIONS = {
|
7
|
+
headers: {
|
8
|
+
accept: 'application/json',
|
9
|
+
user_agent: 'quizlet-ruby client'
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
class Client
|
14
|
+
include Quizlet::Sets
|
15
|
+
|
16
|
+
attr_reader :access_token, :client_id
|
17
|
+
|
18
|
+
def initialize(opts)
|
19
|
+
@access_token = opts[:access_token]
|
20
|
+
@client_id = opts[:client_id]
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(endpoint, params)
|
24
|
+
request(:get, endpoint, params)
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(endpoint, params)
|
28
|
+
request(:post, endpoint, params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def put(endpoint, params)
|
32
|
+
request(:put, endpoint, params)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(endpoint, params)
|
36
|
+
request(:delete, endpoint, params)
|
37
|
+
end
|
38
|
+
|
39
|
+
def request(action, endpoint, params)
|
40
|
+
res = connection.send(action, endpoint, params).env
|
41
|
+
|
42
|
+
if res[:body] && res[:body] != ''
|
43
|
+
JSON.parse res[:body]
|
44
|
+
else
|
45
|
+
{status: res[:status]}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def connection
|
50
|
+
@connection ||= Faraday.new('https://api.quizlet.com/2.0', CONNECTION_OPTIONS) do |conn|
|
51
|
+
conn.request :url_encoded
|
52
|
+
conn.authorization :Bearer, access_token
|
53
|
+
conn.adapter Faraday.default_adapter
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
data/lib/quizlet/sets.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Quizlet
|
2
|
+
module Sets
|
3
|
+
# This actually doesn't look supported
|
4
|
+
def get_sets
|
5
|
+
get('sets', {})
|
6
|
+
end
|
7
|
+
|
8
|
+
def get_set_by_id(id)
|
9
|
+
get('sets/' + id.to_s, {})
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_set_terms_by_id(id)
|
13
|
+
get('sets/' + id.to_s + '/terms', {})
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_set_password_by_id(id)
|
17
|
+
get('sets/' + id.to_s + '/password', {})
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_sets_by_class_id(class_id)
|
21
|
+
get('classes/' + class_id.to_s + '/sets', {})
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_sets_by_user_id(user_id)
|
25
|
+
get('users/' + user_id.to_s + '/sets', {})
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_favorite_sets_by_user_id(user_id)
|
29
|
+
get('users/' + user_id.to_s + '/favorites', {})
|
30
|
+
end
|
31
|
+
|
32
|
+
# Params requires {title, terms[], definitions[], lang_terms, lang_definitions}
|
33
|
+
def add_set(params)
|
34
|
+
post('sets', params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit_set_by_id(id, params)
|
38
|
+
put('sets/' + id.to_s, params)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_set_by_id(id)
|
42
|
+
delete('sets/' + id.to_s, {})
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_term_to_set_by_id(id, params)
|
46
|
+
post('sets/' + id.to_s + '/terms', params)
|
47
|
+
end
|
48
|
+
|
49
|
+
def edit_term_in_set_by_id(set_id, term_id, params)
|
50
|
+
put('sets/' + set_id.to_s + '/terms/' + term_id.to_s, params)
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete_term_in_set_by_id(set_id, term_id)
|
54
|
+
delete('sets/' + set_id.to_s + '/terms/' + term_id.to_s, {})
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'quizlet-ruby'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.date = '2013-04-07'
|
5
|
+
s.summary = "A Ruby wrapper for the Quizlet 2.0 API"
|
6
|
+
s.description = "A Ruby wrapper for the Quizlet 2.0 API"
|
7
|
+
|
8
|
+
s.authors = ["Matthew DuVall"]
|
9
|
+
s.email = 'mduvall89@gmail.com'
|
10
|
+
|
11
|
+
s.required_ruby_version = ">= 1.9.0"
|
12
|
+
s.add_dependency "faraday_middleware"
|
13
|
+
s.add_dependency "json"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.homepage = 'http://www.mattduvall.com'
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quizlet-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matthew DuVall
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday_middleware
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: A Ruby wrapper for the Quizlet 2.0 API
|
47
|
+
email: mduvall89@gmail.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- LICENSE.md
|
54
|
+
- README.md
|
55
|
+
- lib/quizlet.rb
|
56
|
+
- lib/quizlet/client.rb
|
57
|
+
- lib/quizlet/sets.rb
|
58
|
+
- quizlet-ruby.gemspec
|
59
|
+
homepage: http://www.mattduvall.com
|
60
|
+
licenses: []
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.9.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 1.8.24
|
80
|
+
signing_key:
|
81
|
+
specification_version: 3
|
82
|
+
summary: A Ruby wrapper for the Quizlet 2.0 API
|
83
|
+
test_files: []
|
84
|
+
has_rdoc:
|