Class: Interpark::Book::Client
- Inherits:
-
Object
- Object
- Interpark::Book::Client
- Extended by:
- Forwardable
- Defined in:
- lib/interpark/book/client.rb
Constant Summary collapse
- APIS =
{ :search => {:method => "GET", :path => "/api/search.api"} }
Instance Method Summary collapse
- #configuration ⇒ Object
- #configure {|configuration| ... } ⇒ Object
- #get(http, path, data) ⇒ Object
-
#initialize(attrs = {}) ⇒ Client
constructor
A new instance of Client.
- #post(http, path, data) ⇒ Object
- #request(method, path, data) ⇒ Object
- #search(content, options) ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Client
Returns a new instance of Client.
49 50 51 |
# File 'lib/interpark/book/client.rb', line 49 def initialize(attrs = {}) self.configuration.attributes = attrs end |
Instance Method Details
#configuration ⇒ Object
57 58 59 |
# File 'lib/interpark/book/client.rb', line 57 def configuration @configuration ||= Configuration.new end |
#configure {|configuration| ... } ⇒ Object
53 54 55 |
# File 'lib/interpark/book/client.rb', line 53 def configure yield configuration if block_given? end |
#get(http, path, data) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/interpark/book/client.rb', line 73 def get(http, path, data) data = URI.encode_www_form(data) resp, body = http.send_request("GET", "#{path}?#{data}") JSON.parse(resp.body) end |
#post(http, path, data) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/interpark/book/client.rb', line 80 def post(http, path, data) data = URI.encode_www_form(data) resp, body = http.send_request("POST", path, data) JSON.parse(resp.body) end |
#request(method, path, data) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/interpark/book/client.rb', line 61 def request(method, path, data) http = configuration.http data = configuration.data.merge(data) case method when "GET" get(http, path, data) when "POST" post(http, path, data) end end |