Class: Yoyo::Yo
- Inherits:
-
Object
- Object
- Yoyo::Yo
- Defined in:
- lib/yoyo.rb
Instance Attribute Summary collapse
-
#api_connection ⇒ Object
readonly
This is just a reference to the HTTP connection to the YO mothership.
-
#api_token ⇒ Object
readonly
This is your API token.
-
#result ⇒ Object
readonly
Struct containing all relevant data from the Yo request.
Instance Method Summary collapse
-
#initialize(api_token) ⇒ Yo
constructor
You’re going to need an API token to get started.
-
#subscribers_count ⇒ Object
Get the number of subscribers you have.
-
#yo(some_user, opts = {}) ⇒ Object
Say YO to someone from your API account Usage: yo(“PHILCRISSMAN”) Returns a Faraday response, so you can see the HTTP status and errors, if any.
-
#yo_all(opts = {}) ⇒ Object
Say YO to everyone who has ever YO’d your API account Should return an empty body.
Constructor Details
#initialize(api_token) ⇒ Yo
You’re going to need an API token to get started. You can get one from dev.justyo.co/
32 33 34 35 36 37 38 |
# File 'lib/yoyo.rb', line 32 def initialize(api_token) @api_token = api_token @api_connection = Faraday.new(:url => "http://api.justyo.co/") do |f| f.request :url_encoded f.adapter Faraday.default_adapter end end |
Instance Attribute Details
#api_connection ⇒ Object (readonly)
This is just a reference to the HTTP connection to the YO mothership. I mean API.
20 21 22 |
# File 'lib/yoyo.rb', line 20 def api_connection @api_connection end |
#api_token ⇒ Object (readonly)
This is your API token. There are many like it, but this one is yours. See dev.justyo.co/
16 17 18 |
# File 'lib/yoyo.rb', line 16 def api_token @api_token end |
#result ⇒ Object (readonly)
Struct containing all relevant data from the Yo request
result#response => Faraday::Response result#parsed => JSON parsed response body result#error => populated if request error’d :( result#result => horribly named store for success response
28 29 30 |
# File 'lib/yoyo.rb', line 28 def result @result end |
Instance Method Details
#subscribers_count ⇒ Object
Get the number of subscribers you have. That sounds handy. Does YO document this anywhere? I can’t find it. Returns a Faraday response. To get the count, you could:
require 'JSON'
yo = Yoyo::Yo.new('your-token')
count = yo.subscribers_count
response_hash = JSON.parse(count.body)
response_hash['result']
That’s not too hard.
65 66 67 68 |
# File 'lib/yoyo.rb', line 65 def subscribers_count build_result :get, "/subscribers_count/" result.result end |
#yo(some_user, opts = {}) ⇒ Object
Say YO to someone from your API account Usage: yo(“PHILCRISSMAN”) Returns a Faraday response, so you can see the HTTP status and errors, if any
43 44 45 |
# File 'lib/yoyo.rb', line 43 def yo(some_user, opts={}) build_result :post, "/yo/", opts.merge(username: some_user) end |
#yo_all(opts = {}) ⇒ Object
Say YO to everyone who has ever YO’d your API account Should return an empty body. YOs all your subscribers
49 50 51 |
# File 'lib/yoyo.rb', line 49 def yo_all(opts={}) build_result :post, "/yoall/", opts end |