Class: YoClient::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(api_token) ⇒ Client

Constructor

Parameters:

  • api_token (String)

    Yo API Token



9
10
11
12
13
14
15
16
# File 'lib/yo_client.rb', line 9

def initialize(api_token)
  @api_token = api_token
  @faraday = Faraday.new(url: 'http://api.justyo.co') do |faraday|
    faraday.request  :url_encoded
    faraday.response :json
    faraday.adapter  :net_http
  end
end

Instance Method Details

#subscribers_countInteger

Get a number of subscribers

Returns:

  • (Integer)

    number of subscribers



42
43
44
45
46
47
# File 'lib/yo_client.rb', line 42

def subscribers_count
  response = connection_wrapper {
    @faraday.get '/subscribers_count/', token_hash
  }
  response.body['result']
end

#yo(username, options = {}) ⇒ Boolean

Yo to specific user

Parameters:

  • username (String)

    usename to send yo

  • options (Hash) (defaults to: {})

    allowed only link for now

Returns:

  • (Boolean)

    if request has succeed



32
33
34
35
36
37
38
# File 'lib/yo_client.rb', line 32

def yo(username, options = {})
  options.merge!(username: username.upcase)
  response = connection_wrapper {
    @faraday.post '/yo/', token_hash.merge(options)
  }
  response.success?
end

#yoall(options = {}) ⇒ Boolean

Yo to all subscribers

Parameters:

  • options (Hash) (defaults to: {})

    allowed only link for now

Returns:

  • (Boolean)

    if request has succeed



21
22
23
24
25
26
# File 'lib/yo_client.rb', line 21

def yoall(options = {})
  response = connection_wrapper {
    @faraday.post '/yoall/', token_hash.merge(options)
  }
  response.success?
end