simplegeo 0.5.1 → 0.5.3

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.
@@ -8,46 +8,4 @@ For the specific documentation on APIs (and the full list of parameters) see:
8
8
  * http://simplegeo.com/docs/clients-code-libraries/ruby
9
9
  * http://simplegeo.com/docs/tutorials/ruby
10
10
 
11
- == Installation
12
-
13
- Open the Terminal or other UNIX shell and type:
14
-
15
- sudo gem install simplegeo
16
-
17
- == Examples
18
-
19
- Start by requiring SimpleGeo and setting your authentication credentials:
20
-
21
- require 'simple_geo'
22
- SimpleGeo::Client.set_credentials('token', 'secret')
23
-
24
- === Other APIs
25
-
26
- For more examples see: spec/client_spec.rb
27
-
28
- === Building
29
-
30
- rake gemspec
31
- gem build simplegeo.gemspec
32
-
33
- == Note on Patches/Pull Requests
34
-
35
- * Fork the project.
36
- * Make your feature addition or bug fix.
37
- * Add tests for it. This is important so I don't break it in a
38
- future version unintentionally.
39
- * Commit, do not mess with rakefile, version, or history.
40
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
41
- * Send me a pull request. Bonus points for topic branches.
42
-
43
- == Running tests
44
- * Use rspec 2 and run "rspec spec" from the project root to run all of the specs
45
- * You're going to require rspec json oauth fakeweb, vcr and autotest (plus their dependencies)
46
-
47
- == Adding tests
48
- * If you want to add new tests, you will need to put a valid token and secret into a before block - similar to lines 4-6 in spec/client_spec.rb, but you'll have to enter valid credentials.
49
- * Look at spec/features_spec.rb for examples of how to write a vcr test. First time it runs the remote connection. After that it uses the data stored in the vcr/cassette directory. Make sure to sanitize your yml vcr files before committing them by removing your oauth token which is stored there by default.
50
-
51
- == Copyright
52
-
53
- Copyright (c) 2010 Dan Dofter. See LICENSE for details.
11
+ Copyright (c) 2011 SimpleGeo Inc., Brian Ryckbost, Dan Dofter. See LICENSE for details.
@@ -12,11 +12,22 @@ module SimpleGeo
12
12
  Record.parse_geojson_hash(record_hash)
13
13
  end
14
14
 
15
- def set_credentials(token, secret)
15
+ # If you don't supply your credentials, we assume they're set in the environment.
16
+ # Using the environment variables is how you would use the client on Heroku, for example.
17
+ def set_credentials(token=nil, secret=nil)
18
+ token, secret = check_credentials(token, secret)
16
19
  @@connection = Connection.new(token, secret)
17
20
  @@connection.debug = @@debug
18
21
  end
19
22
 
23
+ def check_credentials(token, secret)
24
+ if (token.nil? and secret.nil?)
25
+ token=ENV['SIMPLEGEO_KEY']
26
+ secret=ENV['SIMPLEGEO_SECRET']
27
+ end
28
+ return token, secret
29
+ end
30
+
20
31
  def debug=(debug_flag)
21
32
  @@debug = debug_flag
22
33
  @@connection.debug = @@debug if @@connection
@@ -115,19 +126,24 @@ module SimpleGeo
115
126
  nearby_records
116
127
  end
117
128
 
118
- def get_context(lat, lon)
119
- geojson_hash = get Endpoint.context(lat, lon)
129
+ def get_context(lat, lon, filter=nil)
130
+ geojson_hash = get Endpoint.context(lat, lon, filter)
120
131
  HashUtils.recursively_symbolize_keys geojson_hash
121
132
  end
122
133
 
123
- def get_context_by_address(address)
134
+ def get_context_by_address(address, filter=nil)
124
135
  address = URI.escape(address, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
125
- geojson_hash = get Endpoint.context_by_address(address)
136
+ geojson_hash = get Endpoint.context_by_address(address, filter)
137
+ HashUtils.recursively_symbolize_keys geojson_hash
138
+ end
139
+
140
+ def get_context_ip(ip, filter=nil)
141
+ geojson_hash = get Endpoint.context_ip(ip, filter)
126
142
  HashUtils.recursively_symbolize_keys geojson_hash
127
143
  end
128
144
 
129
- def get_context_ip(ip)
130
- geojson_hash = get Endpoint.context_ip(ip)
145
+ def geocode_from_ip(ip="ip")
146
+ geojson_hash = get Endpoint.geocode_from_ip(ip)
131
147
  HashUtils.recursively_symbolize_keys geojson_hash
132
148
  end
133
149
 
@@ -45,16 +45,32 @@ module SimpleGeo
45
45
  endpoint_url "records/#{layer}/nearby/#{ip}.json", '0.1'
46
46
  end
47
47
 
48
- def context(lat, lon)
49
- endpoint_url "context/#{lat},#{lon}.json", '1.0'
48
+ def context(lat, lon, filter)
49
+ if defined?(filter)
50
+ endpoint_url "context/#{lat},#{lon}.json?filter=#{filter}", '1.0'
51
+ else
52
+ endpoint_url "context/#{lat},#{lon}.json", '1.0'
53
+ end
50
54
  end
51
55
 
52
- def context_by_address(address)
53
- endpoint_url "context/address.json?address=#{address}", '1.0'
56
+ def context_by_address(address, filter)
57
+ if defined?(filter)
58
+ endpoint_url "context/address.json?address=#{address}&filter=#{filter}", '1.0'
59
+ else
60
+ endpoint_url "context/address.json?address=#{address}", '1.0'
61
+ end
54
62
  end
55
63
 
56
- def context_ip(ip)
57
- endpoint_url "context/#{ip}.json", '1.0'
64
+ def context_ip(ip, filter)
65
+ if defined?(filter)
66
+ endpoint_url "context/#{ip}.json?filter=#{filter}", '1.0'
67
+ else
68
+ endpoint_url "context/#{ip}.json", '1.0'
69
+ end
70
+ end
71
+
72
+ def geocode_from_ip(ip)
73
+ endpoint_url "context/#{ip}.json?filter=query", '1.0'
58
74
  end
59
75
 
60
76
  def places(lat, lon, options)
metadata CHANGED
@@ -1,22 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplegeo
3
3
  version: !ruby/object:Gem::Version
4
- hash: 9
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 5
9
- - 1
10
- version: 0.5.1
9
+ - 3
10
+ version: 0.5.3
11
11
  platform: ruby
12
12
  authors:
13
- - Andrew Mager
14
13
  - Brian Ryckbost
14
+ - Andrew Mager
15
15
  autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-04-26 00:00:00 Z
19
+ date: 2011-06-26 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: oauth
@@ -80,7 +80,23 @@ dependencies:
80
80
  version: 1.2.0
81
81
  type: :development
82
82
  version_requirements: *id004
83
- description: A SimpleGeo Ruby client
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ prerelease: false
86
+ requirement: &id005 !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 15
92
+ segments:
93
+ - 1
94
+ - 6
95
+ - 0
96
+ version: 1.6.0
97
+ type: :development
98
+ version_requirements: *id005
99
+ description:
84
100
  email: andrew@simplegeo.com
85
101
  executables: []
86
102
 
@@ -142,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
158
  version: "0"
143
159
  requirements: []
144
160
 
145
- rubyforge_project: nowarning
146
- rubygems_version: 1.7.2
161
+ rubyforge_project:
162
+ rubygems_version: 1.8.5
147
163
  signing_key:
148
164
  specification_version: 3
149
165
  summary: A SimpleGeo Ruby Client