Class: LapisLazuli::API
- Inherits:
-
Object
- Object
- LapisLazuli::API
- Defined in:
- lib/lapis_lazuli/api.rb
Overview
Proxy class to map to sc-proxy
Instance Attribute Summary collapse
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
Instance Method Summary collapse
-
#initialize ⇒ API
constructor
A new instance of API.
- #method_missing(meth, *args, &block) ⇒ Object
-
#respond_to?(meth) ⇒ Boolean
Map any missing method to the conn object or Faraday.
- #set_conn(url, options = nil, &block) ⇒ Object
Constructor Details
#initialize ⇒ API
Returns a new instance of API.
19 20 |
# File 'lib/lapis_lazuli/api.rb', line 19 def initialize() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/lapis_lazuli/api.rb', line 41 def method_missing(meth, *args, &block) if !@conn.nil? and @conn.respond_to? meth return @conn.send(meth.to_s, *args, &block) end begin return Faraday.send(meth.to_s, *args, &block) rescue NoMethodError return super end end |
Instance Attribute Details
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
18 19 20 |
# File 'lib/lapis_lazuli/api.rb', line 18 def conn @conn end |
Instance Method Details
#respond_to?(meth) ⇒ Boolean
Map any missing method to the conn object or Faraday
34 35 36 37 38 39 |
# File 'lib/lapis_lazuli/api.rb', line 34 def respond_to?(meth) if !@conn.nil? and @conn.respond_to? meth return true end return super end |
#set_conn(url, options = nil, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/lapis_lazuli/api.rb', line 22 def set_conn(url, =nil, &block) block = block_given? ? block : Proc.new do |conn| conn.response :xml, :content_type => /\bxml$/ conn.response :json, :content_type => /\bjson$/ conn.adapter Faraday.default_adapter end @conn = Faraday.new(url, , &block) end |