Class: Dopplr::Traveller
- Inherits:
-
Object
- Object
- Dopplr::Traveller
- Defined in:
- lib/dopplr/traveller.rb
Instance Attribute Summary collapse
-
#email_sha1 ⇒ Object
readonly
Returns the value of attribute email_sha1.
-
#icon_id ⇒ Object
readonly
Returns the value of attribute icon_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nick ⇒ Object
readonly
Returns the value of attribute nick.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#travel_today ⇒ Object
readonly
Returns the value of attribute travel_today.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #current_city(options = {}) ⇒ Object
- #fellows(options = {}) ⇒ Object
- #future_trips(options = {}) ⇒ Object
- #home_city(options = {}) ⇒ Object
-
#initialize(client, user = nil) ⇒ Traveller
constructor
A new instance of Traveller.
- #location_on_date(date) ⇒ Object
- #populate ⇒ Object
- #trips(options = {}) ⇒ Object
Constructor Details
#initialize(client, user = nil) ⇒ Traveller
Returns a new instance of Traveller.
5 6 7 8 9 10 |
# File 'lib/dopplr/traveller.rb', line 5 def initialize(client, user = nil) @client = client @params = {} @params[:traveller] = user if user populate end |
Instance Attribute Details
#email_sha1 ⇒ Object (readonly)
Returns the value of attribute email_sha1.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def email_sha1 @email_sha1 end |
#icon_id ⇒ Object (readonly)
Returns the value of attribute icon_id.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def icon_id @icon_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def name @name end |
#nick ⇒ Object (readonly)
Returns the value of attribute nick.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def nick @nick end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def status @status end |
#travel_today ⇒ Object (readonly)
Returns the value of attribute travel_today.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def travel_today @travel_today end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
3 4 5 |
# File 'lib/dopplr/traveller.rb', line 3 def url @url end |
Instance Method Details
#current_city(options = {}) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/dopplr/traveller.rb', line 23 def current_city( = {}) unless @current_city && ![:force] info = @client.get('traveller_info', @params)['traveller'] @current_city = City.new @client, info['current_city']['geoname_id'] end @current_city end |
#fellows(options = {}) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dopplr/traveller.rb', line 59 def fellows( = {}) unless @fellows && ![:force] fellows = @client.get('fellows', @params) fellows['can_see_trips_of'].map! do |fellow| Traveller.new @client, fellow['nick'] end fellows['shows_trips_to'].map! do |fellow| hash = fellow.inject({}) do |memo, (key, value)| memo[key.to_sym] = value memo end Struct.new(*hash.keys).new(*hash.values_at(*hash.keys)) end @fellows = fellows.inject({}) do |memo, (key, value)| memo[key.to_sym] = value memo end end @fellows end |
#future_trips(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/dopplr/traveller.rb', line 49 def future_trips( = {}) unless @future_trips && ![:force] trips = @client.get('future_trips_info', @params)['trip'] @future_trips = trips.map do |trip| Trip.new @client, trip['id'] end end @future_trips end |
#home_city(options = {}) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/dopplr/traveller.rb', line 31 def home_city( = {}) unless @home_city && ![:force] info = @client.get('traveller_info', @params)['traveller'] @home_city = City.new @client, info['home_city']['geoname_id'] end @home_city end |
#location_on_date(date) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/dopplr/traveller.rb', line 80 def location_on_date(date) location = @client.get('location_on_date', @params.merge(:date => date))['location'] location['home'] = City.new(@client, location['home']['geoname_id']) if location['trip'] location['trip'] = Trip.new(@client, location['trip']['id']) end location = location.inject({}) do |memo, (key, value)| memo[key.to_sym] = value memo end location end |
#populate ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dopplr/traveller.rb', line 12 def populate info = @client.get('traveller_info', @params)['traveller'] @nick = info['nick'] @name = info['name'] @status = info['status'] @travel_today = info['travel_today'] @icon_id = info['icon_id'] @email_sha1 = info['sha1email'] @url = info['url'] end |