Class: Dopplr::Client
- Inherits:
-
Object
- Object
- Dopplr::Client
- Defined in:
- lib/dopplr/client.rb
Instance Attribute Summary collapse
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
-
#city(city_id) ⇒ Object
Returns a new City object.
-
#create_session ⇒ Object
Changes @token into a session token.
-
#find_city(name) ⇒ Object
I’m feeling lucky city search.
-
#get(path, params = {}) ⇒ Object
Makes an API call with @token.
-
#initialize(token = nil) ⇒ Client
constructor
A new instance of Client.
-
#login_url(url) ⇒ Object
Returns a URL for getting a token.
-
#search(term, type = :all) ⇒ Object
Performs a search query.
-
#traveller(username = nil) ⇒ Object
Returns a new Traveller object.
-
#trip(trip_id) ⇒ Object
Returns a new Trip object.
Constructor Details
#initialize(token = nil) ⇒ Client
Returns a new instance of Client.
5 6 7 |
# File 'lib/dopplr/client.rb', line 5 def initialize(token=nil) @token = token end |
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
3 4 5 |
# File 'lib/dopplr/client.rb', line 3 def token @token end |
Instance Method Details
#city(city_id) ⇒ Object
Returns a new City object.
45 46 47 |
# File 'lib/dopplr/client.rb', line 45 def city(city_id) City.new(self, city_id) end |
#create_session ⇒ Object
Changes @token into a session token.
29 30 31 |
# File 'lib/dopplr/client.rb', line 29 def create_session @token = get('AuthSubSessionToken')['token'] end |
#find_city(name) ⇒ Object
I’m feeling lucky city search.
50 51 52 |
# File 'lib/dopplr/client.rb', line 50 def find_city(name) city get('city_search', :q => name)['city'][0]['geoname_id'] end |
#get(path, params = {}) ⇒ Object
Makes an API call with @token.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dopplr/client.rb', line 10 def get(path, params={}) params['format'] = 'js' params_uri = URI.escape(params.collect{|key,value| "#{key}=#{value}"}.join('&')) url = "/api/#{path}/?#{params_uri}" http = Net::HTTP.new("www.dopplr.com", 443) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.start do |http| request = Net::HTTP::Get.new url, 'Authorization' => "AuthSub token=\"#{@token}\"" JSON.parse(http.request(request).body) end end |
#login_url(url) ⇒ Object
Returns a URL for getting a token.
24 25 26 |
# File 'lib/dopplr/client.rb', line 24 def login_url(url) return "https://www.dopplr.com/api/AuthSubRequest?scope=#{CGI.escape("http://www.dopplr.com/")}&next=#{CGI.escape(url)}&session=1" end |
#search(term, type = :all) ⇒ Object
Performs a search query.
34 35 36 37 38 39 40 41 42 |
# File 'lib/dopplr/client.rb', line 34 def search(term, type=:all) if type == :all get 'search', :q => term elsif type == :city get 'city_search', :q => term elsif type == :traveller get 'traveller_search', :q => term end end |