Class: Me2API::API
- Inherits:
-
Object
- Object
- Me2API::API
- Defined in:
- lib/me2api/api.rb
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
Instance Method Summary collapse
- #accept_friendship_request(friendship_request_id, message) ⇒ Object
- #create_comment(post_id, body) ⇒ Object
-
#create_post(user_id, body, options = {}) ⇒ Object
options :tag - 태그 :attachments - 첨부 파일.
- #delete_comment(comment_id) ⇒ Object
- #delete_post(post_id) ⇒ Object
- #friendship ⇒ Object
- #get_bands(options = {}) ⇒ Object
- #get_comments(post_id) ⇒ Object
- #get_friends(user_id, options = {}) ⇒ Object
- #get_friendship_requests(user_id) ⇒ Object
- #get_metoos(post_id) ⇒ Object
- #get_person(user_id) ⇒ Object
- #get_post(post_id, options = {}) ⇒ Object
- #get_posts(user_id, options = {}) ⇒ Object
- #get_settings ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #metoo(post_id) ⇒ Object
- #noop ⇒ Object
- #track_comments(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/me2api/api.rb', line 7 def initialize( = {}) = { :appkey => nil, :user_id => nil, :apikey => nil, :logger => Logger.new(STDOUT) }.merge() @logger = [:logger] @agent = Agent.new( :appkey => [:appkey], :user_id => [:user_id], :apikey => [:apikey], :logger => @logger ) end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
5 6 7 |
# File 'lib/me2api/api.rb', line 5 def agent @agent end |
Instance Method Details
#accept_friendship_request(friendship_request_id, message) ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/me2api/api.rb', line 104 def accept_friendship_request(friendship_request_id, ) agent.call( 'accept_friendship_requests', :friendship_request_id => friendship_request_id, :message => ) end |
#create_comment(post_id, body) ⇒ Object
66 67 68 69 |
# File 'lib/me2api/api.rb', line 66 def create_comment(post_id, body) resp = agent.call('create_comment', :post_id => post_id, :body => body) Comment.new(post_id, resp) end |
#create_post(user_id, body, options = {}) ⇒ Object
options
:tag - 태그
:attachments - 첨부 파일
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/me2api/api.rb', line 43 def create_post(user_id, body, = {}) params = {} params['post[body]'] = body params['post[tag]'] = [:tag] if [:tag] if [:attachment] params[:files] = { 'attachment' => [:attachment] } end resp = agent.call("create_post/#{user_id}", params) Post.new(resp) end |
#delete_comment(comment_id) ⇒ Object
71 72 73 74 |
# File 'lib/me2api/api.rb', line 71 def delete_comment(comment_id) resp = agent.call('delete_comment', :comment_id => comment_id) Result.new(resp) end |
#delete_post(post_id) ⇒ Object
54 55 56 57 |
# File 'lib/me2api/api.rb', line 54 def delete_post(post_id) resp = agent.call("delete_post", :post_id => post_id) Result.new(resp) end |
#friendship ⇒ Object
95 96 97 |
# File 'lib/me2api/api.rb', line 95 def friendship raise NotImplementedError.new("friendship unsupported method") end |
#get_bands(options = {}) ⇒ Object
117 118 119 120 |
# File 'lib/me2api/api.rb', line 117 def get_bands( = {}) resp = agent.call('get_bands', ) resp.map { |b| Band.new(b) } end |
#get_comments(post_id) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/me2api/api.rb', line 59 def get_comments(post_id) resp = agent.call("get_comments", :post_id => post_id) resp['comments'].map do |c| Comment.new(post_id, c, :post_permalink => resp['post_permalink']) end end |
#get_friends(user_id, options = {}) ⇒ Object
90 91 92 93 |
# File 'lib/me2api/api.rb', line 90 def get_friends(user_id, = {}) resp = agent.call("get_friends/#{user_id}") resp['friends'].map { |f| Person.new(f) } end |
#get_friendship_requests(user_id) ⇒ Object
99 100 101 102 |
# File 'lib/me2api/api.rb', line 99 def get_friendship_requests(user_id) resp = agent.call("get_friendship_requests/#{user_id}") resp['friendship_requests'].map { |r| FriendshipRequest.new(r) } end |
#get_metoos(post_id) ⇒ Object
80 81 82 83 |
# File 'lib/me2api/api.rb', line 80 def get_metoos(post_id) resp = agent.call('get_metoos', :post_id => post_id) resp['metoos'].map { |m| Metoo.new(post_id, m) } end |
#get_person(user_id) ⇒ Object
24 25 26 27 |
# File 'lib/me2api/api.rb', line 24 def get_person(user_id) resp = agent.call("get_person/#{user_id}") Person.new(resp) end |
#get_post(post_id, options = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/me2api/api.rb', line 29 def get_post(post_id, = {}) [:post_id] = post_id resp = agent.call("get_posts", ) Post.new(resp.first) end |
#get_posts(user_id, options = {}) ⇒ Object
35 36 37 38 |
# File 'lib/me2api/api.rb', line 35 def get_posts(user_id, = {}) resp = agent.call("get_posts/#{user_id}", ) resp.map { |p| Post.new(p) } end |
#get_settings ⇒ Object
112 113 114 115 |
# File 'lib/me2api/api.rb', line 112 def get_settings resp = agent.call('get_settings') Setting.new(resp) end |
#metoo(post_id) ⇒ Object
85 86 87 88 |
# File 'lib/me2api/api.rb', line 85 def metoo(post_id) resp = agent.call('metoo', :post_id => post_id) Result.new(resp) end |
#noop ⇒ Object
122 123 124 125 |
# File 'lib/me2api/api.rb', line 122 def noop resp = agent.call('noop') Result.new(resp) end |
#track_comments(options = {}) ⇒ Object
76 77 78 |
# File 'lib/me2api/api.rb', line 76 def track_comments( = {}) raise NotImplementedError.new("track_comments unsupported method") end |