Class: Draugiem

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

Constant Summary collapse

API_URL =
'http://api.draugiem.lv/json/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_key, user_key = nil) ⇒ Draugiem

Returns a new instance of Draugiem.



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

def initialize app_key, user_key = nil
  @app_key, @user_key = app_key, user_key
end

Instance Attribute Details

#app_keyObject

Returns the value of attribute app_key.



8
9
10
# File 'lib/draugiem.rb', line 8

def app_key
  @app_key
end

#user_keyObject

Returns the value of attribute user_key.



8
9
10
# File 'lib/draugiem.rb', line 8

def user_key
  @user_key
end

Instance Method Details

#add_activity(text, prefix = nil, link = nil, params = {}) ⇒ Object



37
38
39
# File 'lib/draugiem.rb', line 37

def add_activity text, prefix = nil, link = nil, params = {}
  send({action: 'add_activity', text: text, prefix: prefix, link: link}.merge(params))
end

#app_friends(page = 1, limit = 20, return_ids = false) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/draugiem.rb', line 29

def app_friends page = 1, limit = 20, return_ids = false
  resp = send action: 'app_friends', page: page, limit: limit, show: return_ids ? 'ids' : nil
  if return_ids && resp['userids'].any?
    resp = {'total' => resp['total'], 'userids' => resp['userids'].map{|k, v| k.to_i}}
  end
  resp
end

#authorize(auth_code) ⇒ Object



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

def authorize auth_code
  send action: 'authorize', code: auth_code
end

#send(params = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/draugiem.rb', line 14

def send(params = {})
  params[:app]    = app_key
  params[:apikey] = user_key

  JSON.parse(Net::HTTP.post_form(URI.parse(API_URL), params).body)
end

#user_dataObject



25
26
27
# File 'lib/draugiem.rb', line 25

def user_data
  send action: 'userdata'
end