me2api-ruby 0.1.0
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 +18 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +22 -0
- data/README.md +74 -0
- data/Rakefile +29 -0
- data/UNLICENSE.md +24 -0
- data/lib/me2api/agent.rb +139 -0
- data/lib/me2api/api.rb +129 -0
- data/lib/me2api/model/band.rb +4 -0
- data/lib/me2api/model/comment.rb +19 -0
- data/lib/me2api/model/friendship_request.rb +10 -0
- data/lib/me2api/model/metoo.rb +18 -0
- data/lib/me2api/model/person.rb +19 -0
- data/lib/me2api/model/post.rb +12 -0
- data/lib/me2api/model/result.rb +7 -0
- data/lib/me2api/model/setting.rb +6 -0
- data/lib/me2api/model.rb +60 -0
- data/lib/me2api/version.rb +3 -0
- data/lib/me2api.rb +17 -0
- data/me2api-ruby.gemspec +22 -0
- data/test/agent_test.rb +21 -0
- data/test/api_test.rb +223 -0
- data/test/test.png +0 -0
- data/test/test_helper.rb +19 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
me2api-ruby (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
curb (0.8.0)
|
10
|
+
json (1.7.3)
|
11
|
+
rake (0.8.7)
|
12
|
+
tzinfo (0.3.33)
|
13
|
+
|
14
|
+
PLATFORMS
|
15
|
+
ruby
|
16
|
+
|
17
|
+
DEPENDENCIES
|
18
|
+
curb (~> 0.8.0)
|
19
|
+
json (~> 1.7.3)
|
20
|
+
me2api-ruby!
|
21
|
+
rake (~> 0.8.3)
|
22
|
+
tzinfo (~> 0.3.33)
|
data/README.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
me2api-ruby
|
2
|
+
-----------
|
3
|
+
|
4
|
+
A Ruby wrapper for the Me2day API.
|
5
|
+
|
6
|
+
설치
|
7
|
+
====
|
8
|
+
|
9
|
+
gem install me2day-ruby
|
10
|
+
|
11
|
+
사용례
|
12
|
+
=====
|
13
|
+
|
14
|
+
api = Me2API::API.new(
|
15
|
+
:appkey => APPKEY,
|
16
|
+
:user_id => USER_ID,
|
17
|
+
:apikey => APIKEY
|
18
|
+
)
|
19
|
+
|
20
|
+
post = api.create_post(USER_ID, 'hello world')
|
21
|
+
|
22
|
+
참고자료
|
23
|
+
=======
|
24
|
+
|
25
|
+
* Naver 개발자 센터 - 미투데이 API(http://dev.naver.com/openapi/apis/me2day/me2api_intro)
|
26
|
+
|
27
|
+
TODO
|
28
|
+
====
|
29
|
+
|
30
|
+
* 쉬운인증 지원
|
31
|
+
|
32
|
+
Contributors
|
33
|
+
============
|
34
|
+
|
35
|
+
Authors ordered by first contribution.
|
36
|
+
|
37
|
+
* Heungseok Do <codian@gmail.com>
|
38
|
+
|
39
|
+
License
|
40
|
+
=======
|
41
|
+
|
42
|
+
This is free and unencumbered software released into the public domain.
|
43
|
+
For more information, see http://unlicense.org/ or the accompanying UNLICENSE file.
|
44
|
+
|
45
|
+
ChangeLog
|
46
|
+
=========
|
47
|
+
|
48
|
+
## 0.1(2012-06-27)
|
49
|
+
|
50
|
+
First release.
|
51
|
+
|
52
|
+
Features:
|
53
|
+
|
54
|
+
- apikey 인증 지원
|
55
|
+
- 지원 메소드
|
56
|
+
* `get_person`
|
57
|
+
* `get_posts`
|
58
|
+
* `create_post`
|
59
|
+
* `delete_post`
|
60
|
+
* `get_comments`
|
61
|
+
* `create_comment`
|
62
|
+
* `delete_comment`
|
63
|
+
* `get_metoos`
|
64
|
+
* `metoo`
|
65
|
+
* `get_friends`
|
66
|
+
* `get_friendship_requests`
|
67
|
+
* `accept_friendship_request`
|
68
|
+
* `get_settings`
|
69
|
+
* `get_bands`
|
70
|
+
* `noop`
|
71
|
+
|
72
|
+
Bugfixes:
|
73
|
+
|
74
|
+
- 없음
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require 'rake/testtask'
|
5
|
+
begin
|
6
|
+
require 'rdoc/task'
|
7
|
+
rescue LoadError
|
8
|
+
require 'rake/rdoctask'
|
9
|
+
end
|
10
|
+
desc "Run unit tests"
|
11
|
+
Rake::TestTask.new("test_units") do |t|
|
12
|
+
t.pattern = 'test/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
t.warning = true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "generate API documentation to doc/"
|
18
|
+
Rake::RDocTask.new do |rd|
|
19
|
+
rd.rdoc_dir = 'doc/'
|
20
|
+
rd.main = 'README.rdoc'
|
21
|
+
rd.rdoc_files.include 'README.md', 'UNLICENSE.md', 'lib/me2api/api.rb'
|
22
|
+
|
23
|
+
rd.options << '-c utf-8'
|
24
|
+
rd.options << '--line-numbers'
|
25
|
+
rd.options << '--all'
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Default: run the tests'
|
29
|
+
task :default => :test_units
|
data/UNLICENSE.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
2
|
+
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
4
|
+
distribute this software, either in source code form or as a compiled
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
6
|
+
means.
|
7
|
+
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
9
|
+
of this software dedicate any and all copyright interest in the
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
11
|
+
of the public at large and to the detriment of our heirs and
|
12
|
+
successors. We intend this dedication to be an overt act of
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
14
|
+
software under copyright law.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
For more information, please refer to <http://unlicense.org/>
|
data/lib/me2api/agent.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
require 'curb'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Me2API
|
7
|
+
class Me2dayAPIError < StandardError; end
|
8
|
+
class FetchError < Me2dayAPIError; end
|
9
|
+
class NotImplementedError < Me2dayAPIError; end
|
10
|
+
class ServerError < Me2dayAPIError
|
11
|
+
attr_reader :reason
|
12
|
+
|
13
|
+
def initialize(reason)
|
14
|
+
@reason = reason
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"code: #{reason.code}, message: #{reason.message}, desc: #{reason.description}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class Agent
|
23
|
+
attr_accessor :host, :protocol, :appkey, :user_id, :apikey,
|
24
|
+
:open_timeout, :read_timeout, :logger
|
25
|
+
|
26
|
+
# options
|
27
|
+
# :protocol - 'http' or 'https'. API 요청을 위한 프로토콜. 디폴트는 'http'
|
28
|
+
# :host - me2API 서버의 호스트명(도메인명) 디폴트는 'me2day.net'
|
29
|
+
# :appkey - me2API appkey. 발급은 http://me2day.net/me2/app/get_appkey
|
30
|
+
# :user_id - 현재 이용자의 미투데이 아이디
|
31
|
+
# :apikey - 사용자 인증키. 인증키를 이용한 인증방식인 경우 사용됨.
|
32
|
+
# :open_timeout - 커넥션 타임아웃. 초단위로 지정함. 지정하지 않는 경우 5초
|
33
|
+
# :read_timeout - 읽기 타임아웃. 초단위로 지정함. 지정하지 않은 경우 5초
|
34
|
+
# :logger - 로그 파일 경로 또는 Logger 객체 지정 지정하지 않는 경우 콘솔
|
35
|
+
def initialize(options = {})
|
36
|
+
options = {
|
37
|
+
:protocol => 'http',
|
38
|
+
:host => 'me2day.net',
|
39
|
+
:appkey => nil,
|
40
|
+
:user_id => nil,
|
41
|
+
:apikey => nil,
|
42
|
+
:open_timeout => 5,
|
43
|
+
:read_timeout => 5,
|
44
|
+
:logger => Logger.new(STDOUT)
|
45
|
+
}.merge(options)
|
46
|
+
|
47
|
+
@host = options[:host]
|
48
|
+
@protocol = options[:protocol]
|
49
|
+
@appkey = options[:appkey]
|
50
|
+
@user_id = options[:user_id]
|
51
|
+
@apikey = options[:apikey]
|
52
|
+
@open_timeout = options[:open_timeout]
|
53
|
+
@read_timeout = options[:read_timeout]
|
54
|
+
@logger = options[:logger]
|
55
|
+
end
|
56
|
+
|
57
|
+
def api_url(name, params = {})
|
58
|
+
case name
|
59
|
+
when 'get_person', 'get_posts', 'create_post', 'get_friends',
|
60
|
+
'get_friendship_requests'
|
61
|
+
return "#{@protocol}://#{@host}/api/#{name}/#{params[:user_id]}.json"
|
62
|
+
else
|
63
|
+
return "#{@protocol}://#{@host}/api/#{name}.json"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def call(method_name, params = {})
|
68
|
+
url = api_url(method_name, params)
|
69
|
+
|
70
|
+
http = Curl::Easy.new(url)
|
71
|
+
http.max_redirects = 2
|
72
|
+
http.connect_timeout = @open_timeout
|
73
|
+
http.timeout = @read_timeout
|
74
|
+
|
75
|
+
http.headers["me2_application_key"] = @appkey
|
76
|
+
http.headers["User-Agent"] = "ME2API for ruby " + VERSION
|
77
|
+
|
78
|
+
if @user_id && @apikey
|
79
|
+
nonce = generate_nonce
|
80
|
+
cred = nonce + Digest::MD5.hexdigest(nonce + @apikey)
|
81
|
+
|
82
|
+
http.http_auth_types = :basic
|
83
|
+
http.username = @user_id
|
84
|
+
http.password = cred
|
85
|
+
end
|
86
|
+
|
87
|
+
data = []
|
88
|
+
params.each do |k, v|
|
89
|
+
if k == :files
|
90
|
+
http.multipart_form_post = true
|
91
|
+
v.each do |fk, fv|
|
92
|
+
data << Curl::PostField.file(fk, fv.to_s)
|
93
|
+
end
|
94
|
+
else
|
95
|
+
data << Curl::PostField.content(k, v.to_s)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
http.http_post(data)
|
100
|
+
|
101
|
+
case http.response_code
|
102
|
+
when 200
|
103
|
+
return JSON.parse(http.body_str)
|
104
|
+
else
|
105
|
+
reason = JSON.parse(http.body_str) rescue nil
|
106
|
+
if reason
|
107
|
+
r = Result.new(reason)
|
108
|
+
error(r.code)
|
109
|
+
error(r.message)
|
110
|
+
error(r.description)
|
111
|
+
raise ServerError.new(r)
|
112
|
+
else
|
113
|
+
error(http.body_str)
|
114
|
+
raise FetchError.new("HTTP status code: #{http.response_code}")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# 16진수 8자리 문자열 생성
|
120
|
+
def generate_nonce
|
121
|
+
rand(4_294_967_296).to_s(16).downcase.rjust(8, '0')
|
122
|
+
end
|
123
|
+
|
124
|
+
def debug(msg)
|
125
|
+
return unless @logger
|
126
|
+
@logger.debug(msg)
|
127
|
+
end
|
128
|
+
|
129
|
+
def info(msg)
|
130
|
+
return unless @logger
|
131
|
+
@logger.info(msg)
|
132
|
+
end
|
133
|
+
|
134
|
+
def error(msg)
|
135
|
+
return unless @logger
|
136
|
+
@logger.error(msg)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
data/lib/me2api/api.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module Me2API
|
4
|
+
class API
|
5
|
+
attr_reader :agent
|
6
|
+
|
7
|
+
def initialize(options = {})
|
8
|
+
options = {
|
9
|
+
:appkey => nil,
|
10
|
+
:user_id => nil,
|
11
|
+
:apikey => nil,
|
12
|
+
:logger => Logger.new(STDOUT)
|
13
|
+
}.merge(options)
|
14
|
+
|
15
|
+
@logger = options[:logger]
|
16
|
+
@agent = Agent.new(
|
17
|
+
:appkey => options[:appkey],
|
18
|
+
:user_id => options[:user_id],
|
19
|
+
:apikey => options[:apikey],
|
20
|
+
:logger => @logger
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_person(user_id)
|
25
|
+
resp = agent.call('get_person', :user_id => user_id)
|
26
|
+
Person.new(resp)
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_posts(user_id, options = {})
|
30
|
+
options = {
|
31
|
+
:user_id => user_id
|
32
|
+
}.merge(options)
|
33
|
+
resp = agent.call('get_posts', options)
|
34
|
+
resp.map { |p| Post.new(p) }
|
35
|
+
end
|
36
|
+
|
37
|
+
# options
|
38
|
+
# :tag - 태그
|
39
|
+
# :attachments - 첨부 파일
|
40
|
+
def create_post(user_id, body, options = {})
|
41
|
+
params = {}
|
42
|
+
params['post[body]'] = body
|
43
|
+
params['post[tag]'] = options[:tag] if options[:tag]
|
44
|
+
if options[:attachment]
|
45
|
+
params[:files] = { 'attachment' => options[:attachment] }
|
46
|
+
end
|
47
|
+
resp = agent.call('create_post', params)
|
48
|
+
Post.new(resp)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delete_post(post_id)
|
52
|
+
resp = agent.call('delete_post', :post_id => post_id)
|
53
|
+
Result.new(resp)
|
54
|
+
end
|
55
|
+
|
56
|
+
def get_comments(post_id)
|
57
|
+
resp = agent.call('get_comments', :post_id => post_id)
|
58
|
+
resp['comments'].map do |c|
|
59
|
+
Comment.new(post_id, c, :post_permalink => resp['post_permalink'])
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_comment(post_id, body)
|
64
|
+
resp = agent.call('create_comment', :post_id => post_id, :body => body)
|
65
|
+
Comment.new(post_id, resp)
|
66
|
+
end
|
67
|
+
|
68
|
+
def delete_comment(comment_id)
|
69
|
+
resp = agent.call('delete_comment', :comment_id => comment_id)
|
70
|
+
Result.new(resp)
|
71
|
+
end
|
72
|
+
|
73
|
+
def track_comments(options = {})
|
74
|
+
raise NotImplementedError.new("track_comments unsupported method")
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_metoos(post_id)
|
78
|
+
resp = agent.call('get_metoos', :post_id => post_id)
|
79
|
+
resp['metoos'].map { |m| Metoo.new(post_id, m) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def metoo(post_id)
|
83
|
+
resp = agent.call('metoo', :post_id => post_id)
|
84
|
+
Result.new(resp)
|
85
|
+
end
|
86
|
+
|
87
|
+
def get_friends(user_id, options = {})
|
88
|
+
resp = agent.call('get_friends', :user_id => user_id)
|
89
|
+
resp['friends'].map { |f| Person.new(f) }
|
90
|
+
end
|
91
|
+
|
92
|
+
def friendship
|
93
|
+
raise NotImplementedError.new("friendship unsupported method")
|
94
|
+
end
|
95
|
+
|
96
|
+
def get_friendship_requests(user_id)
|
97
|
+
resp = agent.call('get_friendship_requests', :user_id => user_id)
|
98
|
+
resp['friendship_requests'].map { |r| FriendshipRequest.new(r) }
|
99
|
+
end
|
100
|
+
|
101
|
+
def accept_friendship_request(friendship_request_id, message)
|
102
|
+
agent.call(
|
103
|
+
'accept_friendship_requests',
|
104
|
+
:friendship_request_id => friendship_request_id,
|
105
|
+
:message => message
|
106
|
+
)
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_settings
|
110
|
+
resp = agent.call('get_settings')
|
111
|
+
Setting.new(resp)
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_bands(options = {})
|
115
|
+
resp = agent.call('get_bands')
|
116
|
+
resp.map { |b| Band.new(b) }
|
117
|
+
end
|
118
|
+
|
119
|
+
def noop
|
120
|
+
resp = agent.call('noop')
|
121
|
+
Result.new(resp)
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
def wrap_array(array)
|
126
|
+
array.map { |val| wrap(val) }
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Me2API
|
4
|
+
class Comment < Model
|
5
|
+
def initialize(post_id, hash, options = {})
|
6
|
+
super(hash)
|
7
|
+
|
8
|
+
self[:post_id] = post_id
|
9
|
+
self[:post_permalink] = options[:post_permalink]
|
10
|
+
end
|
11
|
+
|
12
|
+
def pub_date
|
13
|
+
unless self[:pub_date].is_a?(Time)
|
14
|
+
self[:pub_date] = Time.parse(self[:pub_date])
|
15
|
+
end
|
16
|
+
self[:pub_date]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Me2API
|
4
|
+
class Metoo < Model
|
5
|
+
def initialize(post_id, hash)
|
6
|
+
super(hash)
|
7
|
+
|
8
|
+
self[:post_id] = post_id
|
9
|
+
end
|
10
|
+
|
11
|
+
def pub_date
|
12
|
+
unless self[:pub_date].is_a?(Time)
|
13
|
+
self[:pub_date] = Time.parse(self[:pub_date])
|
14
|
+
end
|
15
|
+
self[:pub_date]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Me2API
|
4
|
+
class Person < Model
|
5
|
+
def registered
|
6
|
+
unless self[:registered].is_a?(Time)
|
7
|
+
self[:registered] = Time.parse(self[:registered])
|
8
|
+
end
|
9
|
+
self[:registered]
|
10
|
+
end
|
11
|
+
|
12
|
+
def updated
|
13
|
+
unless self[:updated].is_a?(Time)
|
14
|
+
self[:updated] = iso8601_time(self[:updated])
|
15
|
+
end
|
16
|
+
self[:updated]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/me2api/model.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
module Me2API
|
2
|
+
class Model < Hash
|
3
|
+
def initialize(hash)
|
4
|
+
super
|
5
|
+
hash.keys.each { |key| self[key] = hash[key] }
|
6
|
+
end
|
7
|
+
|
8
|
+
def wrap(value)
|
9
|
+
if value.is_a?(Hash) && !value.is_a?(Me2API::Model)
|
10
|
+
Model.new(value)
|
11
|
+
else
|
12
|
+
value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def [](key)
|
17
|
+
key = underscore(key.to_s)
|
18
|
+
if has_key?(key)
|
19
|
+
super(key)
|
20
|
+
else
|
21
|
+
super(key.to_sym)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def []=(key, value)
|
26
|
+
key = underscore(key.to_s).to_sym
|
27
|
+
super(key, wrap(value))
|
28
|
+
end
|
29
|
+
|
30
|
+
def id
|
31
|
+
method_missing(:id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def method_missing(name, *args, &block)
|
35
|
+
self[name]
|
36
|
+
end
|
37
|
+
|
38
|
+
FROM_OR_TO_REGEX = /(\d{4}\-\d{1,2}-\d{1,2}[T|\s]\d{1,2}\:\d{1,2}\:\d{1,2})([\+|\s])(\d{2}\:{0,}\d{2})/
|
39
|
+
def iso8601_time(tstr)
|
40
|
+
if tstr =~ FROM_OR_TO_REGEX && tstr !~ /\+/
|
41
|
+
tstr = tstr.gsub(FROM_OR_TO_REGEX) do |match|
|
42
|
+
if $2 == " "
|
43
|
+
match = $1 + "+" + $3
|
44
|
+
end
|
45
|
+
match
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Time.parse(tstr).utc
|
50
|
+
end
|
51
|
+
|
52
|
+
def underscore(str)
|
53
|
+
str.gsub(/::/, '/').
|
54
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
55
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
56
|
+
tr("-", "_").
|
57
|
+
downcase
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/me2api.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
module Me2API
|
4
|
+
end
|
5
|
+
|
6
|
+
require "me2api/agent"
|
7
|
+
require "me2api/api"
|
8
|
+
|
9
|
+
require "me2api/model"
|
10
|
+
require "me2api/model/result"
|
11
|
+
require "me2api/model/person"
|
12
|
+
require "me2api/model/post"
|
13
|
+
require "me2api/model/comment"
|
14
|
+
require "me2api/model/metoo"
|
15
|
+
require "me2api/model/setting"
|
16
|
+
require "me2api/model/band"
|
17
|
+
require "me2api/model/friendship_request"
|
data/me2api-ruby.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path("../lib", __FILE__)
|
4
|
+
require "me2api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "me2api-ruby"
|
8
|
+
s.version = Me2API::VERSION
|
9
|
+
s.summary = %q{A Ruby wrapper for the Me2day API}
|
10
|
+
s.description = %q{me2API is OpenAPI of me2day.
|
11
|
+
me2api-ruby is a ruby library for the me2API}
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = Dir['test/**/*_test.rb']
|
15
|
+
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
s.authors = ["Heungseok Do"]
|
19
|
+
s.email = ["codian@gmail.com"]
|
20
|
+
|
21
|
+
s.homepage = "https://github.com/me2day/me2api-ruby"
|
22
|
+
end
|
data/test/agent_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../test_helper', __FILE__)
|
2
|
+
|
3
|
+
class AgentTest < Test::Unit::TestCase
|
4
|
+
include Me2APICommon
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@agent = Me2API::Agent.new(
|
8
|
+
:appkey => APPKEY,
|
9
|
+
:user_id => USER_ID,
|
10
|
+
:apikey => APIKEY
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_call
|
15
|
+
resp = nil
|
16
|
+
assert_nothing_raised do
|
17
|
+
resp = @agent.call('get_person', :user_id => 'me2help')
|
18
|
+
end
|
19
|
+
assert_equal('me2help', resp['id'])
|
20
|
+
end
|
21
|
+
end
|
data/test/api_test.rb
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
require File.expand_path('test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
class APITest < Test::Unit::TestCase
|
4
|
+
include Me2APICommon
|
5
|
+
|
6
|
+
def test_get_person
|
7
|
+
person = @api.get_person('sumanpark')
|
8
|
+
assert_equal('sumanpark', person.id)
|
9
|
+
|
10
|
+
assert_kind_of(Time, person.registered)
|
11
|
+
assert_kind_of(Time, person.updated)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_get_posts
|
15
|
+
posts = @api.get_posts('sumanpark')
|
16
|
+
|
17
|
+
assert_kind_of(Array, posts)
|
18
|
+
assert(posts.length > 0)
|
19
|
+
assert_block do
|
20
|
+
res = true
|
21
|
+
posts.each do |post|
|
22
|
+
if !post.is_a?(Me2API::Post) || post.post_id.nil?
|
23
|
+
res = false
|
24
|
+
break
|
25
|
+
end
|
26
|
+
end
|
27
|
+
res
|
28
|
+
end
|
29
|
+
post = posts.first
|
30
|
+
assert_kind_of(Time, post.pub_date)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_create_and_delete_post
|
34
|
+
post = nil
|
35
|
+
assert_nothing_raised do
|
36
|
+
post = @api.create_post(USER_ID, 'hello world.' + Time.now.to_i.to_s)
|
37
|
+
end
|
38
|
+
assert_kind_of(Me2API::Post, post)
|
39
|
+
assert_not_nil(post.post_id)
|
40
|
+
|
41
|
+
resp = nil
|
42
|
+
assert_nothing_raised { resp = @api.delete_post(post.post_id) }
|
43
|
+
assert_equal(0, resp.code)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_get_comments
|
47
|
+
comments = @api.get_comments('pylz3nh-yr5s')
|
48
|
+
|
49
|
+
assert_kind_of(Array, comments)
|
50
|
+
assert(comments.length > 0)
|
51
|
+
assert_block do
|
52
|
+
res = true
|
53
|
+
comments.each do |comment|
|
54
|
+
if !comment.is_a?(Me2API::Comment) || comment.comment_id.nil?
|
55
|
+
res = false
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
res
|
60
|
+
end
|
61
|
+
comment = comments.first
|
62
|
+
assert_kind_of(Time, comment.pub_date)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create_and_delete_comment
|
66
|
+
comment = nil
|
67
|
+
assert_nothing_raised do
|
68
|
+
comment = @api.create_comment('pqgf_-mff', 'hello world.' + Time.now.to_i.to_s)
|
69
|
+
end
|
70
|
+
assert_kind_of(Me2API::Comment, comment)
|
71
|
+
assert_not_nil(comment.comment_id)
|
72
|
+
assert_nothing_raised do
|
73
|
+
post = @api.delete_comment(comment.comment_id)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_get_metoo
|
78
|
+
metoos = @api.get_metoos('pylz3nh-yr5s')
|
79
|
+
|
80
|
+
assert_kind_of(Array, metoos)
|
81
|
+
assert(metoos.length > 0)
|
82
|
+
assert_block do
|
83
|
+
res = true
|
84
|
+
metoos.each do |metoo|
|
85
|
+
if !metoo.is_a?(Me2API::Metoo)
|
86
|
+
res = false
|
87
|
+
break
|
88
|
+
end
|
89
|
+
end
|
90
|
+
res
|
91
|
+
end
|
92
|
+
metoo = metoos.first
|
93
|
+
assert_kind_of(Time, metoo.pub_date)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_metoo
|
97
|
+
e = assert_raise(Me2API::ServerError) do
|
98
|
+
resp = @api.metoo('pylz3nh-yr5s')
|
99
|
+
end
|
100
|
+
# 1004, 파라미터가 올바르지 않습니다, 이미 미투했습니다.
|
101
|
+
assert_equal 1004, e.reason.code
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_get_friends
|
105
|
+
friends = @api.get_friends('sumanpark')
|
106
|
+
|
107
|
+
assert_kind_of(Array, friends)
|
108
|
+
assert(friends.length > 0)
|
109
|
+
assert_block do
|
110
|
+
res = true
|
111
|
+
friends.each do |friend|
|
112
|
+
if !friend.is_a?(Me2API::Person)
|
113
|
+
res = false
|
114
|
+
break
|
115
|
+
end
|
116
|
+
end
|
117
|
+
res
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_get_settings
|
122
|
+
setting = @api.get_settings
|
123
|
+
assert_equal(USER_ID, setting.settings_of)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_get_bands
|
127
|
+
bands = @api.get_bands
|
128
|
+
assert_kind_of(Array, bands)
|
129
|
+
assert(bands.length > 0)
|
130
|
+
assert_block do
|
131
|
+
res = true
|
132
|
+
bands.each do |band|
|
133
|
+
if !band.is_a?(Me2API::Band)
|
134
|
+
res = false
|
135
|
+
break
|
136
|
+
end
|
137
|
+
end
|
138
|
+
res
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def test_noop
|
143
|
+
resp = nil
|
144
|
+
assert_nothing_raised { resp = @api.noop }
|
145
|
+
assert_equal(0, resp.code)
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_noop_fail
|
149
|
+
e = assert_raise(Me2API::ServerError) do
|
150
|
+
@api.agent.user_id = 'unknown'
|
151
|
+
@api.noop
|
152
|
+
end
|
153
|
+
|
154
|
+
assert_equal(1007, e.reason.code)
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_get_friendship_requests
|
158
|
+
resp = @api.get_friendship_requests(USER_ID)
|
159
|
+
assert_block("return objects is not FriendshipRequest") do
|
160
|
+
res = true
|
161
|
+
resp.each do |fr|
|
162
|
+
if !fr.is_a?(Me2API::FriendshipRequest)
|
163
|
+
res = false
|
164
|
+
break
|
165
|
+
end
|
166
|
+
end
|
167
|
+
res
|
168
|
+
end
|
169
|
+
|
170
|
+
assert_block("FriendshipRequest object's `id' is not set") do
|
171
|
+
res = true
|
172
|
+
resp.each do |fr|
|
173
|
+
if fr.id.empty?
|
174
|
+
res = false
|
175
|
+
break
|
176
|
+
end
|
177
|
+
end
|
178
|
+
res
|
179
|
+
end
|
180
|
+
|
181
|
+
assert_block("FriendshipRequest object's `from' is not Person") do
|
182
|
+
res = true
|
183
|
+
resp.each do |fr|
|
184
|
+
if !fr.from.is_a?(Me2API::Person)
|
185
|
+
res = false
|
186
|
+
break
|
187
|
+
end
|
188
|
+
end
|
189
|
+
res
|
190
|
+
end
|
191
|
+
|
192
|
+
assert_block("FriendshipRequest object's `to' is not Person") do
|
193
|
+
res = true
|
194
|
+
resp.each do |fr|
|
195
|
+
if !fr.to.is_a?(Me2API::Person)
|
196
|
+
res = false
|
197
|
+
break
|
198
|
+
end
|
199
|
+
end
|
200
|
+
res
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_create_post_with_tag_and_photo
|
205
|
+
post = nil
|
206
|
+
assert_nothing_raised do
|
207
|
+
post = @api.create_post(
|
208
|
+
USER_ID,
|
209
|
+
'hello world.' + Time.now.to_i.to_s,
|
210
|
+
:tag => '이것은 태그',
|
211
|
+
:attachment => File.expand_path('test.png', File.dirname(__FILE__))
|
212
|
+
)
|
213
|
+
end
|
214
|
+
assert_kind_of(Me2API::Post, post)
|
215
|
+
assert_not_nil(post.post_id)
|
216
|
+
assert_not_nil(post.media)
|
217
|
+
assert_equal('nphoto_inf', post.media.provider)
|
218
|
+
|
219
|
+
resp = nil
|
220
|
+
assert_nothing_raised { resp = @api.delete_post(post.post_id) }
|
221
|
+
assert_equal(0, resp.code)
|
222
|
+
end
|
223
|
+
end
|
data/test/test.png
ADDED
Binary file
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH << File.expand_path("../lib/me2api", File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'me2api'
|
5
|
+
|
6
|
+
module Me2APICommon
|
7
|
+
APPKEY = '40e05bcc74bb61fcfa30ed8ef9ae6107'
|
8
|
+
USER_ID = 'm2test100'
|
9
|
+
APIKEY = '34372730'
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@api = Me2API::API.new(
|
13
|
+
:appkey => APPKEY,
|
14
|
+
:user_id => USER_ID,
|
15
|
+
:apikey => APIKEY,
|
16
|
+
:logger => nil
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: me2api-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Heungseok Do
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-06-27 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: |-
|
22
|
+
me2API is OpenAPI of me2day.
|
23
|
+
me2api-ruby is a ruby library for the me2API
|
24
|
+
email:
|
25
|
+
- codian@gmail.com
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions: []
|
29
|
+
|
30
|
+
extra_rdoc_files: []
|
31
|
+
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- Gemfile
|
35
|
+
- Gemfile.lock
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- UNLICENSE.md
|
39
|
+
- lib/me2api.rb
|
40
|
+
- lib/me2api/agent.rb
|
41
|
+
- lib/me2api/api.rb
|
42
|
+
- lib/me2api/model.rb
|
43
|
+
- lib/me2api/model/band.rb
|
44
|
+
- lib/me2api/model/comment.rb
|
45
|
+
- lib/me2api/model/friendship_request.rb
|
46
|
+
- lib/me2api/model/metoo.rb
|
47
|
+
- lib/me2api/model/person.rb
|
48
|
+
- lib/me2api/model/post.rb
|
49
|
+
- lib/me2api/model/result.rb
|
50
|
+
- lib/me2api/model/setting.rb
|
51
|
+
- lib/me2api/version.rb
|
52
|
+
- me2api-ruby.gemspec
|
53
|
+
- test/agent_test.rb
|
54
|
+
- test/api_test.rb
|
55
|
+
- test/test.png
|
56
|
+
- test/test_helper.rb
|
57
|
+
homepage: https://github.com/me2day/me2api-ruby
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
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
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 1.8.23
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: A Ruby wrapper for the Me2day API
|
90
|
+
test_files:
|
91
|
+
- test/agent_test.rb
|
92
|
+
- test/api_test.rb
|
93
|
+
has_rdoc:
|