Class: Draugiem
- Inherits:
-
Object
- Object
- Draugiem
- Defined in:
- lib/draugiem.rb
Constant Summary collapse
- API_URL =
'http://api.draugiem.lv/json/'
Instance Attribute Summary collapse
-
#app_key ⇒ Object
Returns the value of attribute app_key.
-
#user_key ⇒ Object
Returns the value of attribute user_key.
Instance Method Summary collapse
- #add_activity(text, prefix = nil, link = nil, params = {}) ⇒ Object
- #app_friends(page = 1, limit = 20, return_ids = false) ⇒ Object
- #authorize(auth_code) ⇒ Object
-
#initialize(app_key, user_key = nil) ⇒ Draugiem
constructor
A new instance of Draugiem.
- #send(params = {}) ⇒ Object
- #user_data ⇒ Object
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_key ⇒ Object
Returns the value of attribute app_key.
8 9 10 |
# File 'lib/draugiem.rb', line 8 def app_key @app_key end |
#user_key ⇒ Object
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 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_data ⇒ Object
25 26 27 |
# File 'lib/draugiem.rb', line 25 def user_data send action: 'userdata' end |