Class: Me2API::API

Inherits:
Object
  • Object
show all
Defined in:
lib/me2api/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})    
  options = {
    :appkey => nil,
    :user_id => nil,
    :apikey => nil,
    :logger => Logger.new(STDOUT)
  }.merge(options)
  
  @logger = options[:logger]
  @agent = Agent.new(
    :appkey => options[:appkey],
    :user_id => options[:user_id],
    :apikey => options[:apikey],
    :logger => @logger
  )
end

Instance Attribute Details

#agentObject (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



103
104
105
106
107
108
109
# File 'lib/me2api/api.rb', line 103

def accept_friendship_request(friendship_request_id, message)
  agent.call(
    'accept_friendship_requests', 
    :friendship_request_id => friendship_request_id,
    :message => message
  )
end

#create_comment(post_id, body) ⇒ Object



65
66
67
68
# File 'lib/me2api/api.rb', line 65

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 - 


42
43
44
45
46
47
48
49
50
51
# File 'lib/me2api/api.rb', line 42

def create_post(user_id, body, options = {})
  params = {}
  params['post[body]'] = body
  params['post[tag]'] = options[:tag] if options[:tag]
  if options[:attachment]
    params[:files] = { 'attachment' => options[:attachment] }
  end      
  resp = agent.call("create_post/#{user_id}", params)
  Post.new(resp)
end

#delete_comment(comment_id) ⇒ Object



70
71
72
73
# File 'lib/me2api/api.rb', line 70

def delete_comment(comment_id)
  resp = agent.call('delete_comment', :comment_id => comment_id)
  Result.new(resp)
end

#delete_post(post_id) ⇒ Object



53
54
55
56
# File 'lib/me2api/api.rb', line 53

def delete_post(post_id)
  resp = agent.call("delete_post", :post_id => post_id)
  Result.new(resp)
end

#friendshipObject



94
95
96
# File 'lib/me2api/api.rb', line 94

def friendship
  raise NotImplementedError.new("friendship unsupported method")
end

#get_bands(options = {}) ⇒ Object



116
117
118
119
# File 'lib/me2api/api.rb', line 116

def get_bands(options = {})
  resp = agent.call('get_bands', options)
  resp.map { |b| Band.new(b) }
end

#get_comments(post_id) ⇒ Object



58
59
60
61
62
63
# File 'lib/me2api/api.rb', line 58

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



89
90
91
92
# File 'lib/me2api/api.rb', line 89

def get_friends(user_id, options = {})
  resp = agent.call("get_friends/#{user_id}")
  resp['friends'].map { |f| Person.new(f) }
end

#get_friendship_requests(user_id) ⇒ Object



98
99
100
101
# File 'lib/me2api/api.rb', line 98

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



79
80
81
82
# File 'lib/me2api/api.rb', line 79

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) ⇒ Object



29
30
31
32
# File 'lib/me2api/api.rb', line 29

def get_post(post_id)
  resp = agent.call("get_posts", :post_id => post_id)
  Post.new(resp.first)
end

#get_posts(user_id, options = {}) ⇒ Object



34
35
36
37
# File 'lib/me2api/api.rb', line 34

def get_posts(user_id, options = {})
  resp = agent.call("get_posts/#{user_id}", options)
  resp.map { |p| Post.new(p) }
end

#get_settingsObject



111
112
113
114
# File 'lib/me2api/api.rb', line 111

def get_settings
  resp = agent.call('get_settings')
  Setting.new(resp)
end

#metoo(post_id) ⇒ Object



84
85
86
87
# File 'lib/me2api/api.rb', line 84

def metoo(post_id)
  resp = agent.call('metoo', :post_id => post_id)
  Result.new(resp)
end

#noopObject



121
122
123
124
# File 'lib/me2api/api.rb', line 121

def noop
  resp = agent.call('noop')
  Result.new(resp)
end

#track_comments(options = {}) ⇒ Object



75
76
77
# File 'lib/me2api/api.rb', line 75

def track_comments(options = {})
  raise NotImplementedError.new("track_comments unsupported method")
end