Class: Grepolis::Api::Connection
- Inherits:
-
Object
- Object
- Grepolis::Api::Connection
- Defined in:
- lib/grepolis/api/connection.rb
Instance Attribute Summary collapse
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#world ⇒ Object
Returns the value of attribute world.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #method_missing(meth, *args) ⇒ Object
- #request(type, mapping, response_handler = method(:default_response_handler)) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 |
# File 'lib/grepolis/api/connection.rb', line 8 def initialize( = {}) @world = [:world] @protocol = [:protocol] || 'http' end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/grepolis/api/connection.rb', line 28 def method_missing(meth, *args) begin "Grepolis::Api::#{meth.to_s.camelize}".constantize.new(self) rescue super end end |
Instance Attribute Details
#protocol ⇒ Object
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/grepolis/api/connection.rb', line 6 def protocol @protocol end |
#world ⇒ Object
Returns the value of attribute world.
6 7 8 |
# File 'lib/grepolis/api/connection.rb', line 6 def world @world end |
Instance Method Details
#request(type, mapping, response_handler = method(:default_response_handler)) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/grepolis/api/connection.rb', line 17 def request(type, mapping, response_handler = method(:default_response_handler)) conn = Faraday.new(:url => uri) do |faraday| faraday.response :logger # log requests to STDOUT faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end response = conn.get("/data/#{type}.txt") response_handler.call response, mapping end |
#uri ⇒ Object
13 14 15 |
# File 'lib/grepolis/api/connection.rb', line 13 def uri "#{protocol}://#{world}.grepolis.com" end |