Class: DaumOAuth::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/daum_oauth/blog.rb,
lib/daum_oauth/cafe.rb,
lib/daum_oauth/yozm.rb,
lib/daum_oauth/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
# File 'lib/daum_oauth/client.rb', line 8

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

#authentication_request_token(options = {}) ⇒ Object



30
31
32
# File 'lib/daum_oauth/client.rb', line 30

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

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



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

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

#blog_post_list(blogName, options = {}) ⇒ Object



5
6
7
8
# File 'lib/daum_oauth/blog.rb', line 5

def blog_post_list(blogName, options={})
	puts "/blog/post/list.do?#{options.merge(:blogName => blogName, :output => 'json').collect{|k, v| "#{k}=#{v}"}.join('&')}"
	get("/blog/post/list.do?#{options.merge(:blogName => blogName, :output => 'json').collect{|k, v| "#{k}=#{v}"}.join('&')}")
end

#blog_post_modify(blogName, postId, title, content, tag, options = {}) ⇒ Object



14
15
16
# File 'lib/daum_oauth/blog.rb', line 14

def blog_post_modify(blogName, postId, title, content, tag, options={})
	post("/blog/post/modify.do", options.merge(:blogName => blogName, :postId => postId, :title => title, :content => content, :tag => tag, :output => 'json'))
end

#blog_post_read(blogName, posdId) ⇒ Object



18
19
20
# File 'lib/daum_oauth/blog.rb', line 18

def blog_post_read(blogName, posdId)
	post("/blog/post/read.do?blogName=#{blogName}&postId=#{postId}&output=json") 
end

#blog_post_write(blogName, title, content, tag, options = {}) ⇒ Object



10
11
12
# File 'lib/daum_oauth/blog.rb', line 10

def blog_post_write(blogName, title, content, tag, options={})
	post("/blog/post/write.do", options.merge(:blogName => blogName, :title => title, :content => content, :tag => tag, :output => 'json'))
end

#cafe_alimisObject



9
10
11
# File 'lib/daum_oauth/cafe.rb', line 9

def cafe_alimis
	get("/cafe/alimis.json")
end

#cafe_articles(cafeCode, boardId, page = 1) ⇒ Object



13
14
15
# File 'lib/daum_oauth/cafe.rb', line 13

def cafe_articles(cafeCode, boardId, page=1)
	get("/cafe/articles/#{cafeCode}/#{boardId}.json?page=#{page}")
end

#cafe_boards(cafeCode) ⇒ Object



17
18
19
# File 'lib/daum_oauth/cafe.rb', line 17

def cafe_boards(cafeCode)
	get("/cafe/boards/#{cafeCode}.json")
end

#cafe_favoritesObject



5
6
7
# File 'lib/daum_oauth/cafe.rb', line 5

def cafe_favorites
	get("/cafe/favorite_cafes.json")
end

#cafe_recent_articles(cafeCode) ⇒ Object



21
22
23
# File 'lib/daum_oauth/cafe.rb', line 21

def cafe_recent_articles(cafeCode)
	get("/cafe/recent_articles/#{cafeCode}.json")
end

#request_token(options = {}) ⇒ Object



26
27
28
# File 'lib/daum_oauth/client.rb', line 26

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

#yozm_add(message, options = {}) ⇒ Object

send a message to yozm



28
29
30
31
# File 'lib/daum_oauth/yozm.rb', line 28

def yozm_add(message, options={}) #available options: url_shorten, img_url, parent_msg_id
	#get("/yozm/v1_0/message/add.json?#{options.merge(:message => URI.encode(message)).collect{|k, v| "#{k}=#{v}"}.join('&')}")
	post("/yozm/v1_0/message/add.json", options.merge(:message => message))
end

#yozm_authorized?Boolean

check if authorized to yozm

Returns:

  • (Boolean)


7
8
9
10
# File 'lib/daum_oauth/yozm.rb', line 7

def yozm_authorized?
	 = yozm_show
	!.nil? and ['status'] == 200
end

#yozm_home_timeline(options = {}) ⇒ Object

available options: max_msg_id, since_msg_id, count



47
48
49
# File 'lib/daum_oauth/yozm.rb', line 47

def yozm_home_timeline(options={}) #available options: max_msg_id, since_msg_id, count
	get("/yozm/v1_0/timeline/home.json?#{options.collect{|k,v| "#{k}=#{v}"}.join('&')}")
end

#yozm_join(nickname, options = {}) ⇒ Object

join yozm



39
40
41
# File 'lib/daum_oauth/yozm.rb', line 39

def yozm_join(nickname, options={})	#available options: sex(N/F/M), birthday(1984-11-14), blood_type(N/A/B/AB/O)
	post("/yozm/v1_0/user/join.json", options.merge(:nickname => nickname))
end

#yozm_joined?Boolean

check if a user joined yozm

Returns:

  • (Boolean)


34
35
36
# File 'lib/daum_oauth/yozm.rb', line 34

def yozm_joined?
	get("/yozm/v1_0/user/joined.json")
end

#yozm_search(q, options = {}) ⇒ Object

available options: type(message - default, tag), page, count



43
44
45
# File 'lib/daum_oauth/yozm.rb', line 43

def yozm_search(q, options={}) #available options: type(message - default, tag), page, count
	get("/yozm/v1_0/timeline/search.json?#{options.merge(:q => q).collect{|k,v| "#{k}=#{v}"}.join('&')}")
end

#yozm_show(options = nil) ⇒ Object

gets user info if authorized with oauth, the authorized user’s info will be returned. Otherwise, you can specify nick_name or url_name.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/daum_oauth/yozm.rb', line 15

def yozm_show(options = nil)
	if options.nil?
		return get("/yozm/v1_0/user/show.json")
	elsif options[:url_name]
		return get("/yozm/v1_0/user/show.json?url_name=#{options[:url_name]}")
	elsif options[:nick_name]
		return get("/yozm/v1_0/user/show.json?nick_name=#{options[:nick_name]}")
	else
		return get("/yozm/v1_0/user/show.json")
	end
end

#yozm_user_timeline(url_name, options = {}) ⇒ Object

available options: next(=since_msg_id?, count)



51
52
53
# File 'lib/daum_oauth/yozm.rb', line 51

def yozm_user_timeline(url_name, options={}) #available options: next(=since_msg_id?, count)
	get("/yozm/v1_0/timeline/user.json?#{options.merge(:url_name => url_name).collect{|k,v| "#{k}=#{v}"}.join('&')}")
end