Class: Dopplr::Traveller

Inherits:
Object
  • Object
show all
Defined in:
lib/dopplr/traveller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_sha1Object (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_idObject (readonly)

Returns the value of attribute icon_id.



3
4
5
# File 'lib/dopplr/traveller.rb', line 3

def icon_id
  @icon_id
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/dopplr/traveller.rb', line 3

def name
  @name
end

#nickObject (readonly)

Returns the value of attribute nick.



3
4
5
# File 'lib/dopplr/traveller.rb', line 3

def nick
  @nick
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/dopplr/traveller.rb', line 3

def status
  @status
end

#travel_todayObject (readonly)

Returns the value of attribute travel_today.



3
4
5
# File 'lib/dopplr/traveller.rb', line 3

def travel_today
  @travel_today
end

#urlObject (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(options = {})
  unless @current_city && !options[: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(options = {})
  unless @fellows && !options[: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(options = {})
  unless @future_trips && !options[: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(options = {})
  unless @home_city && !options[: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

#populateObject



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
# File 'lib/dopplr/traveller.rb', line 39

def trips(options = {})
  unless @trips && !options[:force]
    trips = @client.get('trips_info', @params)['trip']
    @trips = trips.map do |trip|
      Trip.new @client, trip['id']
    end
  end
  @trips
end