dopplr 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -18,9 +18,9 @@ Now that you have a single-use token, assign it to the `Dopplr::Client` object a
18
18
  client.token = '1a2b3c4d5e6f' #=> '1a2b3c4d5e6f'
19
19
  client.create_session #=> '3c4d5e6f1a2b'
20
20
 
21
- ### Instantiating and working with objects
21
+ ### Instantiating and returning data from objects
22
22
 
23
- All Dopplr objects are created using the client as a base, you can then branch of from them to dig deeper.
23
+ All Dopplr objects are created using the client as a base.
24
24
 
25
25
  mike = client.traveller #=> Dopplr::Traveller for the token holder
26
26
  chicago = client.city 4887398 #=> Dopplr::City for ID 4887398
@@ -57,4 +57,23 @@ Return a new `Dopplr::City` object without knowing the geoname_id (I'm feeling l
57
57
  portland = client.find_city "Portland"
58
58
 
59
59
  portland.country #=> "United States"
60
- portland.geoname_id #=> 5746545
60
+ portland.geoname_id #=> 5746545
61
+
62
+ ### Working with and creating new trip data
63
+
64
+ Plan a new trip to Portland, OR.
65
+
66
+ portland.add_trip('2010-01-12', '2010-01-19')
67
+ portland_trip = mike.future_trips.last
68
+
69
+ portland_trip.start #=> Tue Jan 12 00:00:00 2010
70
+ portland_trip.city.latitude #=> 45.5235
71
+
72
+ Add some tags and a note to your trip.
73
+
74
+ portland_trip.add_tags :work, :meetup
75
+ portland_trip.add_note "Staying for a week, then heading back home."
76
+
77
+ Trip got canceled? Delete it.
78
+
79
+ portland_trip.delete
data/lib/dopplr.rb CHANGED
@@ -1,10 +1,9 @@
1
1
  $: << File.dirname(__FILE__)
2
2
 
3
3
  require 'rubygems'
4
- require 'time'
5
- require 'cgi'
6
4
  require 'net/https'
7
5
  require 'json'
6
+ require 'time'
8
7
 
9
8
  require 'dopplr/client'
10
9
  require 'dopplr/traveller'
data/lib/dopplr/city.rb CHANGED
@@ -23,5 +23,9 @@ module Dopplr
23
23
  @url = info['url']
24
24
  @localtime = Time.parse info['localtime'].slice(0..-7)
25
25
  end
26
+
27
+ def add_trip(start, finish)
28
+ @client.post 'add_trip', :geoname_id => @geoname_id, :start => start, :finish => finish
29
+ end
26
30
  end
27
31
  end
data/lib/dopplr/client.rb CHANGED
@@ -6,18 +6,27 @@ module Dopplr
6
6
  @token = token
7
7
  end
8
8
 
9
- # Makes an API call with @token.
9
+ # GET request with @token.
10
10
  def get(path, params={})
11
11
  params['format'] = 'js'
12
- params_uri = URI.escape(params.collect{|key,value| "#{key}=#{value}"}.join('&'))
13
- url = "/api/#{path}/?#{params_uri}"
12
+ url = "/api/#{path}/?#{URI.escape(params.collect{|key,value| "#{key}=#{value}"}.join('&'))}"
14
13
  http = Net::HTTP.new("www.dopplr.com", 443)
15
14
  http.use_ssl = true
16
15
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
17
- http.start do |http|
18
- request = Net::HTTP::Get.new url, 'Authorization' => "AuthSub token=\"#{@token}\""
19
- JSON.parse(http.request(request).body)
20
- end
16
+ responce, data = http.get(url, 'Authorization' => "AuthSub token=\"#{@token}\"")
17
+ JSON.parse(data)
18
+ end
19
+
20
+ # POST request with @token.
21
+ def post(path, params={})
22
+ params['format'] = 'js'
23
+ data_string = URI.escape(params.collect{|key,value| "#{key}=#{value}"}.join('&'))
24
+ url = "/api/#{path}"
25
+ http = Net::HTTP.new("www.dopplr.com", 443)
26
+ http.use_ssl = true
27
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
28
+ response, data = http.post(url, data_string, 'Authorization' => "AuthSub token=\"#{@token}\"")
29
+ JSON.parse(data)
21
30
  end
22
31
 
23
32
  # Returns a URL for getting a token.
@@ -39,13 +39,21 @@ module Dopplr
39
39
  def trips(options = {})
40
40
  unless @trips && !options[:force]
41
41
  trips = @client.get('trips_info', @params)['trip']
42
- if !trips.empty?
43
- @trips = trips.map do |trip|
44
- Trip.new @client, trip['id']
45
- end
42
+ @trips = trips.map do |trip|
43
+ Trip.new @client, trip['id']
44
+ end
45
+ end
46
+ @trips
47
+ end
48
+
49
+ def future_trips(options = {})
50
+ unless @future_trips && !options[:force]
51
+ trips = @client.get('future_trips_info', @params)['trip']
52
+ @future_trips = trips.map do |trip|
53
+ Trip.new @client, trip['id']
46
54
  end
47
55
  end
48
- @trips ||= []
56
+ @future_trips
49
57
  end
50
58
 
51
59
  def fellows(options = {})
@@ -68,5 +76,18 @@ module Dopplr
68
76
  end
69
77
  @fellows
70
78
  end
79
+
80
+ def location_on_date(date)
81
+ location = @client.get('location_on_date', @params.merge(:date => date))['location']
82
+ location['home'] = City.new(@client, location['home']['geoname_id'])
83
+ if location['trip']
84
+ location['trip'] = Trip.new(@client, location['trip']['id'])
85
+ end
86
+ location = location.inject({}) do |memo, (key, value)|
87
+ memo[key.to_sym] = value
88
+ memo
89
+ end
90
+ location
91
+ end
71
92
  end
72
93
  end
data/lib/dopplr/trip.rb CHANGED
@@ -27,5 +27,19 @@ module Dopplr
27
27
  end
28
28
  @city
29
29
  end
30
+
31
+ def add_tags(*tags)
32
+ info = @client.post 'add_trip_tags', :trip_id => @trip_id, :tags => tags.join('+')
33
+ @tags = info['trip']['tag']
34
+ end
35
+
36
+ def add_note(note)
37
+ info = @client.post 'add_trip_note', :trip_id => @trip_id, :body => note
38
+ @notes = info['trip']['note']
39
+ end
40
+
41
+ def delete
42
+ @client.post 'delete_trip', :trip_id => @trip_id
43
+ end
30
44
  end
31
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dopplr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Richards
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-06 00:00:00 -04:00
12
+ date: 2009-08-09 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency