geoloqi 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -51,6 +51,17 @@ You can send query string parameters with get requests too:
51
51
  # or
52
52
  geoloqi.get 'location/history?count=2'
53
53
 
54
+ Hashie::Mash support
55
+ ---
56
+ Want to access in a more OOP/JSON style way? Use Hashie::Mash as the response object:
57
+
58
+ require 'geoloqi'
59
+ geoloqi = Geoloqi::Session.new :access_token => 'YOUR OAUTH2 ACCESS TOKEN GOES HERE', :config => {:use_hashie_mash => true}
60
+ response = geoloqi.get 'layer/info/Gx'
61
+ response.layer_id # this works
62
+ response['layer_id'] # this works too
63
+ response[:layer_id] # so does this
64
+
54
65
  Implementing OAuth2
55
66
  ---
56
67
 
@@ -80,8 +91,9 @@ Here is a simple Sinatra example implementing the OAuth2 flow with Geoloqi:
80
91
  end
81
92
 
82
93
  get '/?' do
83
- session[:geoloqi_auth] = geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token?
94
+ geoloqi.get_auth(params[:code], GEOLOQI_REDIRECT_URI) if params[:code] && !geoloqi.access_token?
84
95
  redirect geoloqi.authorize_url(GEOLOQI_REDIRECT_URI) unless geoloqi.access_token?
96
+
85
97
  username = geoloqi.get('account/username')['username']
86
98
  "You have successfully logged in as #{username}!"
87
99
  end
@@ -132,5 +144,4 @@ TODO / Possible projects
132
144
  ---
133
145
  * Plugin for Sinatra
134
146
  * Rails plugin (works fine as-is, but maybe we can make it easier?)
135
- * More Concrete API in addition to the simple one?
136
- * Hashie::Mash and/or SymbolTable support out of the box
147
+ * More Concrete API in addition to the simple one?
data/geoloqi.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.add_development_dependency 'wrong', '= 0.5.0'
21
21
  s.add_development_dependency 'minitest', '= 2.2.2'
22
22
  s.add_development_dependency 'webmock', '= 1.6.4'
23
+ s.add_development_dependency 'hashie', '= 1.0.0'
23
24
  end
@@ -1,9 +1,15 @@
1
1
  module Geoloqi
2
2
  class Config
3
- attr_accessor :client_id, :client_secret, :adapter, :enable_logging, :redirect_uri
3
+ attr_accessor :client_id, :client_secret, :redirect_uri, :adapter, :enable_logging, :use_hashie_mash
4
4
  def initialize(opts={})
5
5
  opts.each {|k,v| send("#{k}=", v)}
6
6
  self.enable_logging ||= false
7
+ self.use_hashie_mash ||= false
8
+ begin
9
+ require 'hashie' if self.use_hashie_mash && !defined?(Hashie::Mash)
10
+ rescue LoadError
11
+ raise Error, "You've requested Hashie::Mash, but the gem is not available. Don't set use_hashie_mash in your config, or install the hashie gem"
12
+ end
7
13
  raise ArgumentError, 'enable_logging must be boolean' unless [true, false].include? self.enable_logging
8
14
  end
9
15
 
@@ -15,4 +21,4 @@ module Geoloqi
15
21
  !client_secret.nil? && !client_secret.empty?
16
22
  end
17
23
  end
18
- end
24
+ end
data/lib/geoloqi/error.rb CHANGED
@@ -12,4 +12,5 @@ module Geoloqi
12
12
  end
13
13
 
14
14
  class Error < StandardError; end
15
+ class ArgumentError < ArgumentError; end
15
16
  end
@@ -54,11 +54,11 @@ module Geoloqi
54
54
  end
55
55
  end
56
56
 
57
- json = JSON.parse response.body
58
- raise ApiError.new(json['error'], json['error_description']) if json.is_a?(Hash) && json['error']
57
+ hash = JSON.parse response.body
58
+ raise ApiError.new(hash['error'], hash['error_description']) if hash.is_a?(Hash) && hash['error']
59
59
  rescue Geoloqi::ApiError
60
60
  raise Error.new('Unable to procure fresh access token from API on second attempt') if retry_attempt > 0
61
- if json['error'] == 'expired_token'
61
+ if hash['error'] == 'expired_token'
62
62
  renew_access_token!
63
63
  retry_attempt += 1
64
64
  retry
@@ -66,7 +66,7 @@ module Geoloqi
66
66
  fail
67
67
  end
68
68
  end
69
- json
69
+ @config.use_hashie_mash ? Hashie::Mash.new(hash) : hash
70
70
  end
71
71
 
72
72
  def renew_access_token!
@@ -1,5 +1,5 @@
1
1
  module Geoloqi
2
2
  def self.version
3
- '0.9.9'
3
+ '0.9.10'
4
4
  end
5
5
  end
data/spec/geoloqi_spec.rb CHANGED
@@ -48,7 +48,7 @@ describe Geoloqi::Config do
48
48
  end
49
49
 
50
50
  it 'throws exception if non-boolean value is fed to logging' do
51
- expect { rescuing { Geoloqi.config(:client_id => '', :client_secret => '', :enable_logging => :cats )}.class == ArgumentError }
51
+ expect { rescuing { Geoloqi.config(:client_id => '', :client_secret => '', :enable_logging => :cats )}.class == Geoloqi::ArgumentError }
52
52
  end
53
53
 
54
54
  it 'correctly checks booleans for client_id and client_secret' do
@@ -75,6 +75,19 @@ describe Geoloqi::Session do
75
75
  end
76
76
  end
77
77
 
78
+ describe 'with access token and hashie mash' do
79
+ before do
80
+ @session = Geoloqi::Session.new :access_token => 'access_token1234', :config => {:use_hashie_mash => true}
81
+ end
82
+
83
+ it 'should respond to method calls in addition to hash' do
84
+ response = @session.get 'account/username'
85
+ expect { response['username'] == 'bulbasaurrulzok' }
86
+ expect { response.username == 'bulbasaurrulzok' }
87
+ expect { response[:username] == 'bulbasaurrulzok' }
88
+ end
89
+ end
90
+
78
91
  describe 'with access token and no config' do
79
92
  before do
80
93
  @session = Geoloqi::Session.new :access_token => ARGV[2]
@@ -196,17 +209,17 @@ describe Geoloqi::Session do
196
209
  expect { (5..10).include? (Time.rfc2822(response[:expires_at]) - (Time.now+86400)).abs }
197
210
  end
198
211
 
199
- it 'does not refresh when never expires' do
212
+ it 'does not refresh when never expires' do
200
213
  WebMock.disable_net_connect!
201
214
  begin
202
215
  response = @session.get_auth '1234', 'http://neverexpires.example.com/'
203
216
  ensure
204
217
  WebMock.allow_net_connect!
205
218
  end
206
-
219
+
207
220
  expect { @session.auth[:expires_in] == '0' }
208
221
  expect { @session.auth[:expires_at].nil? }
209
-
222
+
210
223
  WebMock.disable_net_connect!
211
224
  begin
212
225
  response = @session.get 'account/username'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: geoloqi
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.9
5
+ version: 0.9.10
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyle Drake
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-07-06 00:00:00 -07:00
14
+ date: 2011-07-07 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -69,6 +69,17 @@ dependencies:
69
69
  version: 1.6.4
70
70
  type: :development
71
71
  version_requirements: *id005
72
+ - !ruby/object:Gem::Dependency
73
+ name: hashie
74
+ prerelease: false
75
+ requirement: &id006 !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - "="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.0.0
81
+ type: :development
82
+ version_requirements: *id006
72
83
  description: Powerful, flexible, lightweight interface to the awesome Geoloqi platform API! Uses Faraday, and can be used with Ruby 1.9 and EM-Synchrony for really fast, highly concurrent development.
73
84
  email:
74
85
  - kyledrake@gmail.com