Class: Hey::Yo

Inherits:
Dispatcher show all
Defined in:
lib/hey/yo.rb

Overview

Sends requests to the Yo API yo endpoints.

Instance Attribute Summary

Attributes inherited from Dispatcher

#api_token

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dispatcher

#initialize

Constructor Details

This class inherits a constructor from Hey::Dispatcher

Class Method Details

.all(*args) ⇒ Object

Sends a request to the yoall endpoint using the API token set on the Hey module.



41
42
43
# File 'lib/hey/yo.rb', line 41

def self.all *args
  new.all *args
end

.user(*args) ⇒ Object

Sends a request to a user using the yo endpoint. Raises a MissingAPITokenError error if an API token hasn’t been set on the Hey module.

Hey::Yo.user "worldcup"
Hey::Yo.user "worldcup", link: "http://example.com"


51
52
53
# File 'lib/hey/yo.rb', line 51

def self.user *args
  new.user *args
end

Instance Method Details

#all(params = {}) ⇒ Object

Sends a request to the yoall endpoint. Raises a MissingAPITokenError error if an API token hasn’t been set on the Hey module or Yo instance. Accepts an optional hash of additional parameters to send with the request.



13
14
15
# File 'lib/hey/yo.rb', line 13

def all params = {}
  post 'yoall', params
end

#subscribersObject

Accesses subscriber endpoints using the same API key

yo = Hey::Yo.new api_token: '3858f62230ac3c915f300c664312c63f'
yo.subscribers.count
# => 2


35
36
37
# File 'lib/hey/yo.rb', line 35

def subscribers
  Hey::Subscriber.new api_token: api_token
end

#user(name, params = {}) ⇒ Object

Sends a request to a user using the yo endpoint. Raises a MissingAPITokenError error if an API token hasn’t been set on the Hey module or Yo instance. Accepts an optional hash of additional parameters to send with the request.

Hey::Yo.new.user "worldcup"
Hey::Yo.new.user "worldcup", link: "http://example.com"


25
26
27
28
# File 'lib/hey/yo.rb', line 25

def user name, params = {}
  params.merge! username: name
  post 'yo', params
end