Class: ClassleaksOAuth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/classleaks_oauth/client.rb,
lib/classleaks_oauth/methods.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



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

def initialize(options = {})
	@consumer_key = options[:consumer_key]
	@consumer_secret = options[:consumer_secret]
	@token = options[:token]
	@secret = options[:secret]
	#@callback_url = options[:callback_url]
end

Instance Method Details

#add_assessment(lecture_id, content, overall, fairness, easiness, options = {}) ⇒ Object



59
60
61
# File 'lib/classleaks_oauth/methods.rb', line 59

def add_assessment(lecture_id, content, overall, fairness, easiness, options={})
	post("/v1/assessments/add.json", options.merge(:lecture_id => lecture_id, :content => content, :overall => overall, :fairness => fairness, :easiness => easiness))
end

#add_talk(lecture_id, content, options = {}) ⇒ Object



46
47
48
# File 'lib/classleaks_oauth/methods.rb', line 46

def add_talk(lecture_id, content, options={})
	post("/v1/talks/add.json", options.merge(:lecture_id => lecture_id, :content => content))
end

#assessments(lecture_id, options = {}) ⇒ Object

assessment



55
56
57
# File 'lib/classleaks_oauth/methods.rb', line 55

def assessments(lecture_id, options={})
    get("/v1/assessments.json?#{options.merge(:lecture_id => lecture_id).collect{|k,v| "#{k}=#{v}"}.join('&')}")
end

#authentication_request_token(options = {}) ⇒ Object



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

def authentication_request_token(options = {})
	request_token(options)
end

#authorize(token, secret, options = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/classleaks_oauth/client.rb', line 19

def authorize(token, secret, options = {})
	request_token = OAuth::RequestToken.new(
		consumer, token, secret
	)
	@access_token = request_token.get_access_token(options)
	@token = @access_token.token
	@secret = @access_token.secret
	@access_token
end

#authorized?Boolean

oauth

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
# File 'lib/classleaks_oauth/methods.rb', line 5

def authorized?
			begin
  	oauth_response = access_token.get("/oauth/test_request")
oauth_response.code.to_i == 200
			rescue Exception => e
false
			end
end

#delete(path, body = '', headers = {}) ⇒ Object



59
60
61
62
63
# File 'lib/classleaks_oauth/client.rb', line 59

def delete(path, body='', headers={})
	headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
	oauth_response = access_token.delete(path, headers)
	JSON.parse oauth_response.body
end

#destroy_assessment(assessment_id) ⇒ Object



67
68
69
# File 'lib/classleaks_oauth/methods.rb', line 67

def destroy_assessment(assessment_id)
	post("/v1/assessments/destroy/#{assessment_id}.json")
end

#destroy_talk(talk_id) ⇒ Object



50
51
52
# File 'lib/classleaks_oauth/methods.rb', line 50

def destroy_talk(talk_id)
	post("/v1/talks/destroy/#{talk_id}.json")
end

#get(path, headers = {}) ⇒ Object

get, post, put, delete will be private methods.. now public just for test



39
40
41
42
43
44
# File 'lib/classleaks_oauth/client.rb', line 39

def get(path, headers={})
	headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
	oauth_response = access_token.get(path, headers)
	# JSON.parse oauth_response.body
	oauth_response.body
end

#join(username, fullname, password, options = {}) ⇒ Object

user



16
17
18
# File 'lib/classleaks_oauth/methods.rb', line 16

def join(username, fullname, password, options={})
  post("/v1/users/join.json", options.merge(:username => username, :fullname => fullname, :password => password))
end

#lecture_add(lecture_id, options = {}) ⇒ Object



33
34
35
# File 'lib/classleaks_oauth/methods.rb', line 33

def lecture_add(lecture_id, options={})
	post("/v1/lectures/add/#{lecture_id}.json", options)
end

#lecture_delete(lecture_id, options = {}) ⇒ Object



37
38
39
# File 'lib/classleaks_oauth/methods.rb', line 37

def lecture_delete(lecture_id, options={})
	post("/v1/lectures/delete/#{lecture_id}.json", options)
end

#my_lecturesObject



29
30
31
# File 'lib/classleaks_oauth/methods.rb', line 29

def my_lectures
  get("/v1/lectures/my.json")
end

#post(path, body = '', headers = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/classleaks_oauth/client.rb', line 46

def post(path, body='', headers={})
	headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
	oauth_response = access_token.post(path, body, headers)
	# JSON.parse oauth_response.body
	oauth_response.body
end

#put(path, body = '', headers = {}) ⇒ Object



53
54
55
56
57
# File 'lib/classleaks_oauth/client.rb', line 53

def put(path, body='', headers={})
	headers.merge!("User-Agent" => "classleaks_oauth gem v#{ClassleaksOAuth::VERSION}")
	oauth_response = access_token.put(path, body, headers)
	JSON.parse oauth_response.body
end

#request_token(options = {}) ⇒ Object



29
30
31
# File 'lib/classleaks_oauth/client.rb', line 29

def request_token(options={})
	consumer.get_request_token(options)
end

#search_lecture(university_id, keyword) ⇒ Object

university, lecture traversing



21
22
23
# File 'lib/classleaks_oauth/methods.rb', line 21

def search_lecture(university_id, keyword)
  get("/search/lecture?university_id=#{university_id}&keyword=#{keyword}")
end

#search_university(keyword) ⇒ Object



25
26
27
# File 'lib/classleaks_oauth/methods.rb', line 25

def search_university(keyword)
	get("/search/university?keyword=#{keyword}")
end

#talks(lecture_id, options = {}) ⇒ Object

talk



42
43
44
# File 'lib/classleaks_oauth/methods.rb', line 42

def talks(lecture_id, options={})
  get("/v1/talks.json?#{options.merge(:lecture_id => lecture_id).collect{|k,v| "#{k}=#{v}"}.join('&')}")
end

#update_assessment(assessment_id, content, overall, fairness, easiness, options = {}) ⇒ Object



63
64
65
# File 'lib/classleaks_oauth/methods.rb', line 63

def update_assessment(assessment_id, content, overall, fairness, easiness, options={})
	post("/v1/assessments/update/#{assessment_id}.json", options.merge(:content => content, :overall => overall, :fairness => fairness, :easiness => easiness))
end