Class: MapmyindiaRuby::Base

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/mapmyindia_ruby/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, url = 'https://api.mapmyindia.com/v3') ⇒ Base

Returns a new instance of Base.



12
13
14
15
# File 'lib/mapmyindia_ruby/base.rb', line 12

def initialize(key, url='https://api.mapmyindia.com/v3')
   self.class.base_uri url
  @key = key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/mapmyindia_ruby/base.rb', line 10

def key
  @key
end

Instance Method Details

#distance(params) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/mapmyindia_ruby/base.rb', line 36

def distance(params)
  params.merge!({ :lic_key => @key,
    :fun => 'star_dists'
  })
  response = self.class.get("",{ :query => params })
  JSON.parse(response.body)
end

#geocoding(query_string) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/mapmyindia_ruby/base.rb', line 17

def geocoding(query_string)
  params = { :lic_key => @key,
    :q => query_string,
    :fun => 'geocode'
  }
  response = self.class.get("",{ :query => params })
  GeoAddr.build(response)
end

#map_tile_image(params, path) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/mapmyindia_ruby/base.rb', line 44

def map_tile_image(params, path)
  params.merge!({ :lic_key => @key,
    :fun => 'still_map'
  })     
  response = self.class.get("",{ :query => params })
  File.open(path,'wb'){|f| f.write(response.body)}
end

#reverse_geocoding(lat, lng) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/mapmyindia_ruby/base.rb', line 26

def reverse_geocoding(lat,lng)
  params = { :lic_key => @key,
    :lat => lat,
    :lng => lng,
    :fun => 'rev_geocode'
  }
  response = self.class.get("",{ :query => params })
  GeoAddr.build(response)
end