Class: Yoxruby::Client
- Inherits:
-
Object
- Object
- Yoxruby::Client
- Defined in:
- lib/yoxruby.rb
Constant Summary collapse
- API_BASE_URL =
"https://api.justyo.co"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
writeonly
Sets the attribute access_token.
-
#api_token ⇒ Object
writeonly
Sets the attribute api_token.
Instance Method Summary collapse
- #add_contacts(username) ⇒ Object
- #contacts ⇒ Object
-
#initialize(api_token = nil, access_token = nil) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #set_api_token(username, password) ⇒ Object
- #subscribers ⇒ Object
- #unread ⇒ Object
- #yo(**options) ⇒ Object
- #yoall(**options) ⇒ Object
Constructor Details
#initialize(api_token = nil, access_token = nil) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 |
# File 'lib/yoxruby.rb', line 11 def initialize(api_token=nil, access_token=nil) if api_token != nil @api_token = api_token end if access_token !=nil @access_token = access_token end @httpclient = HTTPClient.new end |
Instance Attribute Details
#access_token=(value) ⇒ Object (writeonly)
Sets the attribute access_token
7 8 9 |
# File 'lib/yoxruby.rb', line 7 def access_token=(value) @access_token = value end |
#api_token=(value) ⇒ Object (writeonly)
Sets the attribute api_token
7 8 9 |
# File 'lib/yoxruby.rb', line 7 def api_token=(value) @api_token = value end |
Instance Method Details
#add_contacts(username) ⇒ Object
58 59 60 61 62 |
# File 'lib/yoxruby.rb', line 58 def add_contacts(username) url = API_BASE_URL + "/contacts/?access_token=#{@access_token}" res = @httpclient.post(url, {username: username}) JSON.parse res.body end |
#contacts ⇒ Object
52 53 54 55 56 |
# File 'lib/yoxruby.rb', line 52 def contacts url = API_BASE_URL + "/contacts/?access_token=#{@access_token}" res = @httpclient.get(url) JSON.parse res.body end |
#me ⇒ Object
46 47 48 49 50 |
# File 'lib/yoxruby.rb', line 46 def me url = API_BASE_URL + "/me/?access_token=#{@access_token}" res = @httpclient.get(url) JSON.parse res.body end |
#set_api_token(username, password) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/yoxruby.rb', line 21 def set_api_token(username, password) url = API_BASE_URL + "/rpc/login" res = @httpclient.post(url, {username: username, password: password}) res = JSON.parse(res.body) token = "" if res.has_key?('api_token') token = res['api_token'] end @api_token = token end |
#subscribers ⇒ Object
64 65 66 67 68 |
# File 'lib/yoxruby.rb', line 64 def subscribers url = API_BASE_URL + "/subscribers_count/?api_token=#{@api_token}" res = @httpclient.get(url) JSON.parse res.body end |
#unread ⇒ Object
40 41 42 43 44 |
# File 'lib/yoxruby.rb', line 40 def unread url = API_BASE_URL + "/yos/?access_token=#{@access_token}" res = @httpclient.get(url) JSON.parse res.body end |
#yo(**options) ⇒ Object
36 37 38 |
# File 'lib/yoxruby.rb', line 36 def yo(**) just_yo("/yo/", ) end |
#yoall(**options) ⇒ Object
32 33 34 |
# File 'lib/yoxruby.rb', line 32 def yoall(**) just_yo("/yoall/", ) end |