Class: Cloudmate::Client
- Inherits:
-
Object
- Object
- Cloudmate::Client
- Defined in:
- lib/cloudmate/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #configure {|config| ... } ⇒ Object
- #connection ⇒ Object
- #geocode(options) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #route(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
8 9 10 |
# File 'lib/cloudmate/client.rb', line 8 def initialize(={}) @config = Configuration.new() end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/cloudmate/client.rb', line 6 def config @config end |
Instance Method Details
#configure {|config| ... } ⇒ Object
12 13 14 |
# File 'lib/cloudmate/client.rb', line 12 def configure yield config end |
#connection ⇒ Object
16 17 18 |
# File 'lib/cloudmate/client.rb', line 16 def connection @connection ||= Connection.new end |
#geocode(options) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cloudmate/client.rb', line 20 def geocode() url = "http://geocoding.cloudmade.com/#{config.api_key}/geocoding/v2/find.js" .each do |name, value| if value.respond_to?(:join) [name] = value.join(',') elsif value.kind_of?(Hash) [name] = value.map { |k, v| "#{k}:#{v}" }.join(';') end end connection.request(:get, url, ) end |
#route(options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cloudmate/client.rb', line 34 def route() points = .delete(:points) route_type = .delete(:type) { 'car' } route_type_modifier = .delete(:type_modifier) coords = points[1..-2].flatten.join(',') coords = [points.first, coords.empty? ? nil : "%5B#{coords}%5D", points.last].compact.flatten.join(',') url = "http://routes.cloudmade.com/#{config.api_key}/api/0.3" url = [url, coords, route_type, route_type_modifier].compact.join('/') url << '.js' connection.request(:get, url, ) end |