classleaks_oauth 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest +5 -0
- data/Rakefile +14 -0
- data/classleaks_oauth.gemspec +29 -0
- data/lib/classleaks_oauth.rb +8 -0
- data/lib/classleaks_oauth/client.rb +85 -0
- data/lib/classleaks_oauth/methods.rb +72 -0
- metadata +78 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('classleaks_oauth', '0.1.1') do |p|
|
6
|
+
p.description = 'Classleaks OAuth API client library for ruby'
|
7
|
+
p.url = 'http://github.com/thefron/classleaks'
|
8
|
+
p.author = 'Hoseong Hwang'
|
9
|
+
p.email = 'thefron@wafflestudio.com'
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{classleaks_oauth}
|
5
|
+
s.version = "0.1.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Hoseong Hwang"]
|
9
|
+
s.date = %q{2011-04-27}
|
10
|
+
s.description = %q{Classleaks OAuth API client library for ruby}
|
11
|
+
s.email = %q{thefron@wafflestudio.com}
|
12
|
+
s.extra_rdoc_files = ["lib/classleaks_oauth.rb", "lib/classleaks_oauth/client.rb", "lib/classleaks_oauth/methods.rb"]
|
13
|
+
s.files = ["Manifest", "Rakefile", "lib/classleaks_oauth.rb", "lib/classleaks_oauth/client.rb", "lib/classleaks_oauth/methods.rb", "classleaks_oauth.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/thefron/classleaks}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Classleaks_oauth"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{classleaks_oauth}
|
18
|
+
s.rubygems_version = %q{1.6.2}
|
19
|
+
s.summary = %q{Classleaks OAuth API client library for ruby}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
=begin
|
2
|
+
require 'daum_oauth/yozm'
|
3
|
+
require 'daum_oauth/cafe'
|
4
|
+
require 'daum_oauth/blog'
|
5
|
+
=end
|
6
|
+
require 'classleaks_oauth/methods'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
module ClassleaksOAuth
|
10
|
+
class Client
|
11
|
+
def initialize(options = {})
|
12
|
+
@consumer_key = options[:consumer_key]
|
13
|
+
@consumer_secret = options[:consumer_secret]
|
14
|
+
@token = options[:token]
|
15
|
+
@secret = options[:secret]
|
16
|
+
#@callback_url = options[:callback_url]
|
17
|
+
end
|
18
|
+
|
19
|
+
def authorize(token, secret, options = {})
|
20
|
+
request_token = OAuth::RequestToken.new(
|
21
|
+
consumer, token, secret
|
22
|
+
)
|
23
|
+
@access_token = request_token.get_access_token(options)
|
24
|
+
@token = @access_token.token
|
25
|
+
@secret = @access_token.secret
|
26
|
+
@access_token
|
27
|
+
end
|
28
|
+
|
29
|
+
def request_token(options={})
|
30
|
+
consumer.get_request_token(options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def authentication_request_token(options = {})
|
34
|
+
request_token(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
#get, post, put, delete will be private methods.. now public just for test
|
38
|
+
|
39
|
+
def get(path, headers={})
|
40
|
+
headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
|
41
|
+
oauth_response = access_token.get(path, headers)
|
42
|
+
# JSON.parse oauth_response.body
|
43
|
+
oauth_response.body
|
44
|
+
end
|
45
|
+
|
46
|
+
def post(path, body='', headers={})
|
47
|
+
headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
|
48
|
+
oauth_response = access_token.post(path, body, headers)
|
49
|
+
# JSON.parse oauth_response.body
|
50
|
+
oauth_response.body
|
51
|
+
end
|
52
|
+
|
53
|
+
def put(path, body='', headers={})
|
54
|
+
headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
|
55
|
+
oauth_response = access_token.put(path, body, headers)
|
56
|
+
JSON.parse oauth_response.body
|
57
|
+
end
|
58
|
+
|
59
|
+
def delete(path, body='', headers={})
|
60
|
+
headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
|
61
|
+
oauth_response = access_token.delete(path, headers)
|
62
|
+
JSON.parse oauth_response.body
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def consumer
|
68
|
+
@consumer ||= OAuth::Consumer.new(
|
69
|
+
@consumer_key,
|
70
|
+
@consumer_secret,
|
71
|
+
{
|
72
|
+
:site => 'http://api.classmating.net',
|
73
|
+
:request_token_path => '/oauth/request_token',
|
74
|
+
:access_token_path => '/oauth/access_token',
|
75
|
+
:authorize_path => '/oauth/authorize'
|
76
|
+
}
|
77
|
+
)
|
78
|
+
end
|
79
|
+
|
80
|
+
def access_token
|
81
|
+
@access_token ||= OAuth::AccessToken.new(consumer, @token, @secret)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module ClassleaksOAuth
|
2
|
+
class Client
|
3
|
+
|
4
|
+
#oauth
|
5
|
+
def authorized?
|
6
|
+
begin
|
7
|
+
oauth_response = access_token.get("/oauth/test_request")
|
8
|
+
oauth_response.code.to_i == 200
|
9
|
+
rescue Exception => e
|
10
|
+
false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
#user
|
15
|
+
|
16
|
+
def join(username, fullname, password, options={})
|
17
|
+
post("/v1/users/join.json", options.merge(:username => username, :fullname => fullname, :password => password))
|
18
|
+
end
|
19
|
+
|
20
|
+
#university, lecture traversing
|
21
|
+
def search_lecture(university_id, keyword)
|
22
|
+
get("/search/lecture?university_id=#{university_id}&keyword=#{keyword}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def search_university(keyword)
|
26
|
+
get("/search/university?keyword=#{keyword}")
|
27
|
+
end
|
28
|
+
|
29
|
+
def my_lectures
|
30
|
+
get("/v1/lectures/my.json")
|
31
|
+
end
|
32
|
+
|
33
|
+
def lecture_add(lecture_id, options={})
|
34
|
+
post("/v1/lectures/add/#{lecture_id}.json", options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def lecture_delete(lecture_id, options={})
|
38
|
+
post("/v1/lectures/delete/#{lecture_id}.json", options)
|
39
|
+
end
|
40
|
+
|
41
|
+
#talk
|
42
|
+
def talks(lecture_id, options={})
|
43
|
+
get("/v1/talks.json?#{options.merge(:lecture_id => lecture_id).collect{|k,v| "#{k}=#{v}"}.join('&')}")
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_talk(lecture_id, content, options={})
|
47
|
+
post("/v1/talks/add.json", options.merge(:lecture_id => lecture_id, :content => content))
|
48
|
+
end
|
49
|
+
|
50
|
+
def destroy_talk(talk_id)
|
51
|
+
post("/v1/talks/destroy/#{talk_id}.json")
|
52
|
+
end
|
53
|
+
|
54
|
+
#assessment
|
55
|
+
def assessments(lecture_id, options={})
|
56
|
+
get("/v1/assessments.json?#{options.merge(:lecture_id => lecture_id).collect{|k,v| "#{k}=#{v}"}.join('&')}")
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_assessment(lecture_id, content, overall, fairness, easiness, options={})
|
60
|
+
post("/v1/assessments/add.json", options.merge(:lecture_id => lecture_id, :content => content, :overall => overall, :fairness => fairness, :easiness => easiness))
|
61
|
+
end
|
62
|
+
|
63
|
+
def update_assessment(assessment_id, content, overall, fairness, easiness, options={})
|
64
|
+
post("/v1/assessments/update/#{assessment_id}.json", options.merge(:content => content, :overall => overall, :fairness => fairness, :easiness => easiness))
|
65
|
+
end
|
66
|
+
|
67
|
+
def destroy_assessment(assessment_id)
|
68
|
+
post("/v1/assessments/destroy/#{assessment_id}.json")
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: classleaks_oauth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Hoseong Hwang
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-04-27 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: Classleaks OAuth API client library for ruby
|
23
|
+
email: thefron@wafflestudio.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files:
|
29
|
+
- lib/classleaks_oauth.rb
|
30
|
+
- lib/classleaks_oauth/client.rb
|
31
|
+
- lib/classleaks_oauth/methods.rb
|
32
|
+
files:
|
33
|
+
- Manifest
|
34
|
+
- Rakefile
|
35
|
+
- lib/classleaks_oauth.rb
|
36
|
+
- lib/classleaks_oauth/client.rb
|
37
|
+
- lib/classleaks_oauth/methods.rb
|
38
|
+
- classleaks_oauth.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/thefron/classleaks
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --line-numbers
|
46
|
+
- --inline-source
|
47
|
+
- --title
|
48
|
+
- Classleaks_oauth
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
hash: 11
|
66
|
+
segments:
|
67
|
+
- 1
|
68
|
+
- 2
|
69
|
+
version: "1.2"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: classleaks_oauth
|
73
|
+
rubygems_version: 1.6.2
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Classleaks OAuth API client library for ruby
|
77
|
+
test_files: []
|
78
|
+
|