Class: Yoxruby::Client

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

Constant Summary collapse

API_BASE_URL =
"https://api.justyo.co"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Parameters:

  • value

    the value to set the attribute access_token to.



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

Parameters:

  • value

    the value to set the attribute api_token to.



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

#contactsObject



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

#meObject



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

#subscribersObject



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

#unreadObject



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(**options)
    just_yo("/yo/", options)
end

#yoall(**options) ⇒ Object



32
33
34
# File 'lib/yoxruby.rb', line 32

def yoall(**options)
    just_yo("/yoall/", options)
end