Module: Favor::Api::Client
- Defined in:
- lib/favor/api/client.rb,
lib/favor/api/client/version.rb
Defined Under Namespace
Classes: Response
Constant Summary collapse
- API_ENDPOINT =
'http://widget.favor.life/api/v1'- VERSION =
"0.1.0"- @@options =
{ method: 'get' }
Class Method Summary collapse
- .configure {|@@options| ... } ⇒ Object
-
.image_detail(article_id, position, opts = {}) ⇒ Object
Show detail of the photo.
-
.image_search(article_id, opts = {}) ⇒ Object
Search image by article_id.
-
.options ⇒ Object
Default search options.
-
.options=(opts) ⇒ Object
Set default search options.
- .send_request(opts) ⇒ Object
Class Method Details
.configure {|@@options| ... } ⇒ Object
29 30 31 32 |
# File 'lib/favor/api/client.rb', line 29 def self.configure(&proc) fail ArgumentError, "Block is required." unless block_given? yield end |
.image_detail(article_id, position, opts = {}) ⇒ Object
Show detail of the photo.
42 43 44 45 46 47 |
# File 'lib/favor/api/client.rb', line 42 def self.image_detail(article_id, position, opts = {}) opts[:path] = '/photo.json' opts[:a] = article_id opts[:n] = position self.send_request(opts) end |
.image_search(article_id, opts = {}) ⇒ Object
Search image by article_id
35 36 37 38 39 |
# File 'lib/favor/api/client.rb', line 35 def self.image_search(article_id, opts = {}) opts[:path] = '/photo_list.json' opts[:a] = article_id self.send_request(opts) end |
.options ⇒ Object
Default search options
20 21 22 |
# File 'lib/favor/api/client.rb', line 20 def self. end |
.options=(opts) ⇒ Object
Set default search options
25 26 27 |
# File 'lib/favor/api/client.rb', line 25 def self.=(opts) = opts end |
.send_request(opts) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/favor/api/client.rb', line 49 def self.send_request(opts) opts = self..merge(opts) if self. http_response = call_api(opts) res = Response.new(http_response) unless http_response.kind_of? Net::HTTPSuccess err_msg = "HTTP Response: #{http_response.code} #{http_response.message}" err_msg += " - #{res.error}" if res.error fail Favor::Api::RequestError, err_msg end res end |