Class: HackernewsRuby::Client
- Inherits:
-
Object
- Object
- HackernewsRuby::Client
- Extended by:
- Forwardable
- Includes:
- Request
- Defined in:
- lib/hackernews_ruby/client.rb
Instance Attribute Summary collapse
-
#api_url ⇒ Object
Returns the value of attribute api_url.
-
#api_version ⇒ Object
Returns the value of attribute api_version.
Instance Method Summary collapse
-
#changed(params = {}) ⇒ Object
changed returns a hash of updates for profiles and items HackernewsRuby::Client.new.changed.
- #connection ⇒ Object
-
#get_item(id, params = {}) ⇒ Object
get_item expects an ID call it like this HackernewsRuby::Client.new.get_item(2324).
-
#get_user(id, params = {}) ⇒ Object
get_user expects a username HackernewsRuby::Client.new.get_user(‘allcentury’).
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
-
#top_stories(params = {}) ⇒ Object
top_stories returns an array of the top 100 storeis HackernewsRuby::Client.new.top_stories.
Methods included from Request
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
12 13 14 15 16 17 18 19 |
# File 'lib/hackernews_ruby/client.rb', line 12 def initialize(={}) @api_url = "https://hacker-news.firebaseio.com" @api_version = "v0" @api_url = [:api_url].nil? ? api_url : [:api_url] @api_version = [:api_version].nil? ? @api_version : [:api_version] reload_config end |
Instance Attribute Details
#api_url ⇒ Object
Returns the value of attribute api_url.
9 10 11 |
# File 'lib/hackernews_ruby/client.rb', line 9 def api_url @api_url end |
#api_version ⇒ Object
Returns the value of attribute api_version.
9 10 11 |
# File 'lib/hackernews_ruby/client.rb', line 9 def api_version @api_version end |
Instance Method Details
#changed(params = {}) ⇒ Object
changed returns a hash of updates for profiles and items HackernewsRuby::Client.new.changed
60 61 62 63 |
# File 'lib/hackernews_ruby/client.rb', line 60 def changed(params={}) url = "/#{HackernewsRuby.api_version}/updates.json" get(url, params) end |
#connection ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hackernews_ruby/client.rb', line 21 def connection params = {} @connection = Faraday.new(url: @api_url, params: params, headers: default_headers, ssl: { verify: true } ) do |faraday| faraday.use FaradayMiddleware::Mashify faraday.use FaradayMiddleware::ParseJson, content_type: /\bjson$/ faraday.use FaradayMiddleware::FollowRedirects faraday.adapter Faraday.default_adapter end end |
#get_item(id, params = {}) ⇒ Object
get_item expects an ID call it like this HackernewsRuby::Client.new.get_item(2324)
36 37 38 39 |
# File 'lib/hackernews_ruby/client.rb', line 36 def get_item(id, params={}) url = "/#{HackernewsRuby.api_version}/item/#{id}.json" get(url, params) end |
#get_user(id, params = {}) ⇒ Object
get_user expects a username HackernewsRuby::Client.new.get_user(‘allcentury’)
44 45 46 47 |
# File 'lib/hackernews_ruby/client.rb', line 44 def get_user(id, params={}) url = "/#{HackernewsRuby.api_version}/user/#{id}.json" get(url, params) end |
#top_stories(params = {}) ⇒ Object
top_stories returns an array of the top 100 storeis HackernewsRuby::Client.new.top_stories
52 53 54 55 |
# File 'lib/hackernews_ruby/client.rb', line 52 def top_stories(params={}) url = "/#{HackernewsRuby.api_version}/topstories.json" get(url, params) end |