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
- #home_city(options = {}) ⇒ Object
-
#initialize(client, user = nil) ⇒ Traveller
constructor
A new instance of Traveller.
- #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
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dopplr/traveller.rb', line 51 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 |
#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 |
#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 |
#trips(options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/dopplr/traveller.rb', line 39 def trips( = {}) unless @trips && ![:force] trips = @client.get('trips_info', @params)['trip'] if !trips.empty? @trips = trips.map do |trip| Trip.new @client, trip['id'] end end end @trips ||= [] end |