Class: Readability::Client
- Inherits:
-
Object
- Object
- Readability::Client
- Defined in:
- lib/readability/client.rb
Constant Summary collapse
- BASE_API =
"/api/rest/v1"
Instance Attribute Summary collapse
-
#resources ⇒ Object
Returns the value of attribute resources.
Instance Method Summary collapse
- #format_query(resource, args) ⇒ Object (also: #to_url)
- #get(resource = "", args = {}) ⇒ Object
-
#initialize(token) ⇒ Client
constructor
A new instance of Client.
- #parameterize(params) ⇒ Object
Constructor Details
#initialize(token) ⇒ Client
8 9 10 11 12 13 |
# File 'lib/readability/client.rb', line 8 def initialize(token) @token = token.dup # get available resource types @resources = get end |
Instance Attribute Details
#resources ⇒ Object
Returns the value of attribute resources.
4 5 6 |
# File 'lib/readability/client.rb', line 4 def resources @resources end |
Instance Method Details
#format_query(resource, args) ⇒ Object Also known as: to_url
27 28 29 30 31 32 33 |
# File 'lib/readability/client.rb', line 27 def format_query(resource, args) = args.dup query = "#{BASE_API}/#{resource}" query << "/#{options.delete :id}" if .include? :id query << "?#{parameterize(options)}" unless .empty? query end |
#get(resource = "", args = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/readability/client.rb', line 15 def get(resource="", args={}) response = @token.get(format_query(resource, args)) case response when Net::HTTPSuccess data = JSON.parse(response.body) data = data[resource.to_s] unless resource.blank? || args.include?(:id) data else raise StandardError, "Could not get data for those params." end end |
#parameterize(params) ⇒ Object
36 37 38 |
# File 'lib/readability/client.rb', line 36 def parameterize(params) URI.escape(params.collect{|k,v| "#{k}=#{v}"}.join('&')) end |