me2api-ruby 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +11 -0
- data/lib/me2api/agent.rb +4 -12
- data/lib/me2api/api.rb +19 -17
- data/lib/me2api/version.rb +1 -1
- data/test/agent_test.rb +2 -2
- data/test/api_test.rb +10 -1
- metadata +3 -3
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -45,6 +45,17 @@ For more information, see http://unlicense.org/ or the accompanying UNLICENSE fi
|
|
45
45
|
ChangeLog
|
46
46
|
=========
|
47
47
|
|
48
|
+
## 0.2.1 (2012-06-30)
|
49
|
+
|
50
|
+
Features:
|
51
|
+
- Me2API::API#get_post 메소드 추가.
|
52
|
+
|
53
|
+
## 0.2.0 (2012-06-30)
|
54
|
+
|
55
|
+
Features:
|
56
|
+
- 밴드 멤버를 위한 Member 모델 추가
|
57
|
+
- Band.leader를 Member 모델로 wrap
|
58
|
+
|
48
59
|
## 0.1.1 (2012-06-29)
|
49
60
|
|
50
61
|
Features:
|
data/lib/me2api/agent.rb
CHANGED
@@ -54,20 +54,12 @@ module Me2API
|
|
54
54
|
@logger = options[:logger]
|
55
55
|
end
|
56
56
|
|
57
|
-
def api_url(
|
58
|
-
|
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
|
57
|
+
def api_url(url)
|
58
|
+
"#{@protocol}://#{@host}/api/#{url}.json"
|
65
59
|
end
|
66
60
|
|
67
|
-
def call(
|
68
|
-
|
69
|
-
|
70
|
-
http = Curl::Easy.new(url)
|
61
|
+
def call(url, params = {})
|
62
|
+
http = Curl::Easy.new(api_url(url))
|
71
63
|
http.max_redirects = 2
|
72
64
|
http.connect_timeout = @open_timeout
|
73
65
|
http.timeout = @read_timeout
|
data/lib/me2api/api.rb
CHANGED
@@ -20,20 +20,22 @@ module Me2API
|
|
20
20
|
:logger => @logger
|
21
21
|
)
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def get_person(user_id)
|
25
|
-
resp = agent.call(
|
25
|
+
resp = agent.call("get_person/#{user_id}")
|
26
26
|
Person.new(resp)
|
27
27
|
end
|
28
|
+
|
29
|
+
def get_post(post_id)
|
30
|
+
resp = agent.call("get_posts", :post_id => post_id)
|
31
|
+
Post.new(resp.first)
|
32
|
+
end
|
28
33
|
|
29
34
|
def get_posts(user_id, options = {})
|
30
|
-
|
31
|
-
:user_id => user_id
|
32
|
-
}.merge(options)
|
33
|
-
resp = agent.call('get_posts', options)
|
35
|
+
resp = agent.call("get_posts/#{user_id}", options)
|
34
36
|
resp.map { |p| Post.new(p) }
|
35
37
|
end
|
36
|
-
|
38
|
+
|
37
39
|
# options
|
38
40
|
# :tag - 태그
|
39
41
|
# :attachments - 첨부 파일
|
@@ -44,17 +46,17 @@ module Me2API
|
|
44
46
|
if options[:attachment]
|
45
47
|
params[:files] = { 'attachment' => options[:attachment] }
|
46
48
|
end
|
47
|
-
resp = agent.call(
|
49
|
+
resp = agent.call("create_post/#{user_id}", params)
|
48
50
|
Post.new(resp)
|
49
51
|
end
|
50
|
-
|
52
|
+
|
51
53
|
def delete_post(post_id)
|
52
|
-
resp = agent.call(
|
54
|
+
resp = agent.call("delete_post", :post_id => post_id)
|
53
55
|
Result.new(resp)
|
54
56
|
end
|
55
|
-
|
57
|
+
|
56
58
|
def get_comments(post_id)
|
57
|
-
resp = agent.call(
|
59
|
+
resp = agent.call("get_comments", :post_id => post_id)
|
58
60
|
resp['comments'].map do |c|
|
59
61
|
Comment.new(post_id, c, :post_permalink => resp['post_permalink'])
|
60
62
|
end
|
@@ -85,19 +87,19 @@ module Me2API
|
|
85
87
|
end
|
86
88
|
|
87
89
|
def get_friends(user_id, options = {})
|
88
|
-
resp = agent.call(
|
90
|
+
resp = agent.call("get_friends/#{user_id}")
|
89
91
|
resp['friends'].map { |f| Person.new(f) }
|
90
92
|
end
|
91
93
|
|
92
94
|
def friendship
|
93
95
|
raise NotImplementedError.new("friendship unsupported method")
|
94
96
|
end
|
95
|
-
|
97
|
+
|
96
98
|
def get_friendship_requests(user_id)
|
97
|
-
resp = agent.call(
|
99
|
+
resp = agent.call("get_friendship_requests/#{user_id}")
|
98
100
|
resp['friendship_requests'].map { |r| FriendshipRequest.new(r) }
|
99
101
|
end
|
100
|
-
|
102
|
+
|
101
103
|
def accept_friendship_request(friendship_request_id, message)
|
102
104
|
agent.call(
|
103
105
|
'accept_friendship_requests',
|
@@ -105,7 +107,7 @@ module Me2API
|
|
105
107
|
:message => message
|
106
108
|
)
|
107
109
|
end
|
108
|
-
|
110
|
+
|
109
111
|
def get_settings
|
110
112
|
resp = agent.call('get_settings')
|
111
113
|
Setting.new(resp)
|
data/lib/me2api/version.rb
CHANGED
data/test/agent_test.rb
CHANGED
@@ -14,8 +14,8 @@ class AgentTest < Test::Unit::TestCase
|
|
14
14
|
def test_call
|
15
15
|
resp = nil
|
16
16
|
assert_nothing_raised do
|
17
|
-
resp = @agent.call('
|
17
|
+
resp = @agent.call('get_posts', :post_id => 'pyxdhvf-yr5s')
|
18
18
|
end
|
19
|
-
assert_equal('
|
19
|
+
assert_equal('pyxdhvf-yr5s', resp.first['post_id'])
|
20
20
|
end
|
21
21
|
end
|
data/test/api_test.rb
CHANGED
@@ -30,6 +30,13 @@ class APITest < Test::Unit::TestCase
|
|
30
30
|
assert_kind_of(Time, post.pub_date)
|
31
31
|
end
|
32
32
|
|
33
|
+
def test_get_post
|
34
|
+
post = @api.get_post('pyxdhvf-yr5s')
|
35
|
+
|
36
|
+
assert_kind_of(Me2API::Post, post)
|
37
|
+
assert_equal('pyxdhvf-yr5s', post.post_id)
|
38
|
+
end
|
39
|
+
|
33
40
|
def test_create_and_delete_post
|
34
41
|
post = nil
|
35
42
|
assert_nothing_raised do
|
@@ -223,6 +230,7 @@ class APITest < Test::Unit::TestCase
|
|
223
230
|
|
224
231
|
def test_get_bands
|
225
232
|
bands = @api.get_bands
|
233
|
+
assert_kind_of(Array, bands)
|
226
234
|
assert(bands.length > 0)
|
227
235
|
band = bands.first
|
228
236
|
assert_equal(BAND_ID, band.band_id)
|
@@ -231,7 +239,8 @@ class APITest < Test::Unit::TestCase
|
|
231
239
|
|
232
240
|
def test_get_bands_with_band_id
|
233
241
|
bands = @api.get_bands(:band_id => BAND_ID)
|
234
|
-
|
242
|
+
assert_kind_of(Array, bands)
|
243
|
+
assert_equal(1, bands.length)
|
235
244
|
band = bands.first
|
236
245
|
assert_equal(BAND_ID, band.band_id)
|
237
246
|
assert_equal(USER_ID, band.leader.id)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: me2api-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Heungseok Do
|