four_ruby 0.1.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/.document +5 -0
- data/Gemfile +18 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +20 -0
- data/README.md +24 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/config/foursquare_keys.example.yml +3 -0
- data/four_ruby.gemspec +87 -0
- data/lib/four_ruby.rb +7 -0
- data/lib/four_ruby/base.rb +130 -0
- data/lib/four_ruby/oauth2.rb +53 -0
- data/spec/four_ruby_spec.rb +104 -0
- data/spec/spec_helper.rb +16 -0
- metadata +239 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
gem 'rspec'
|
14
|
+
end
|
15
|
+
|
16
|
+
gem 'oauth2'
|
17
|
+
gem 'hashie'
|
18
|
+
gem 'httparty'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.2)
|
5
|
+
crack (0.1.8)
|
6
|
+
diff-lcs (1.1.2)
|
7
|
+
faraday (0.5.3)
|
8
|
+
addressable (~> 2.2.2)
|
9
|
+
multipart-post (~> 1.0.1)
|
10
|
+
rack (>= 1.1.0, < 2)
|
11
|
+
git (1.2.5)
|
12
|
+
hashie (0.4.0)
|
13
|
+
httparty (0.6.1)
|
14
|
+
crack (= 0.1.8)
|
15
|
+
jeweler (1.5.2)
|
16
|
+
bundler (~> 1.0.0)
|
17
|
+
git (>= 1.2.5)
|
18
|
+
rake
|
19
|
+
multi_json (0.0.5)
|
20
|
+
multipart-post (1.0.1)
|
21
|
+
oauth2 (0.1.0)
|
22
|
+
faraday (~> 0.5.0)
|
23
|
+
multi_json (~> 0.0.4)
|
24
|
+
rack (1.2.1)
|
25
|
+
rake (0.8.7)
|
26
|
+
rcov (0.9.9)
|
27
|
+
rspec (2.4.0)
|
28
|
+
rspec-core (~> 2.4.0)
|
29
|
+
rspec-expectations (~> 2.4.0)
|
30
|
+
rspec-mocks (~> 2.4.0)
|
31
|
+
rspec-core (2.4.0)
|
32
|
+
rspec-expectations (2.4.0)
|
33
|
+
diff-lcs (~> 1.1.2)
|
34
|
+
rspec-mocks (2.4.0)
|
35
|
+
shoulda (2.11.3)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler (~> 1.0.0)
|
42
|
+
hashie
|
43
|
+
httparty
|
44
|
+
jeweler (~> 1.5.2)
|
45
|
+
oauth2
|
46
|
+
rcov
|
47
|
+
rspec
|
48
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Andrew Latimer
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# FourRuby
|
2
|
+
|
3
|
+
### Description
|
4
|
+
FourRuby is a super-simple Ruby API wrapper for Foursquare.
|
5
|
+
|
6
|
+
### Examples
|
7
|
+
|
8
|
+
# You can pass in a path to OAuth2 to a YAML file, or you can pass in the id/secret directly.
|
9
|
+
@four = FourRuby::Base.new(FourRuby::OAuth2.new('config/foursquare_keys.yml'))
|
10
|
+
@four.venues.search(:ll => '31.794872,-106.290592') # find 4sq locations near my hometown
|
11
|
+
@four.to_json # => run the above query, and return the json response as a hash
|
12
|
+
# Add query=coffeee to the query
|
13
|
+
@four.venues.search(:query => 'coffee')
|
14
|
+
@four.to_json
|
15
|
+
# You can also treat the FourRuby::Base object like a hash directly, without calling to_json
|
16
|
+
@four["response"]
|
17
|
+
|
18
|
+
### Caveats
|
19
|
+
|
20
|
+
FourRuby doesn't support any calls that require post or an OAuth2 token. That severely diminishes its usefulness, I know, but I haven't had the time to add that in yet.
|
21
|
+
|
22
|
+
### License
|
23
|
+
|
24
|
+
FourRuby is released under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "four_ruby"
|
16
|
+
gem.homepage = "http://github.com/ahlatimer/four_ruby"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{A Ruby API wrapper for Foursquare.}
|
19
|
+
gem.description = %Q{A simple Ruby API wrapper for Foursquare.}
|
20
|
+
gem.email = "andrew@elpasoera.com"
|
21
|
+
gem.authors = ["Andrew Latimer"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
|
27
|
+
gem.add_runtime_dependency 'httparty'
|
28
|
+
gem.add_runtime_dependency 'hashie'
|
29
|
+
gem.add_runtime_dependency 'oauth2'
|
30
|
+
end
|
31
|
+
Jeweler::RubygemsDotOrgTasks.new
|
32
|
+
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
35
|
+
t.rspec_opts = ["--color", "--format doc"]
|
36
|
+
end
|
37
|
+
|
38
|
+
namespace :spec do
|
39
|
+
desc "Run specs with RCov"
|
40
|
+
RSpec::Core::RakeTask.new('rcov') do |t|
|
41
|
+
t.rspec_opts = ["--color"]
|
42
|
+
t.rcov = true
|
43
|
+
t.rcov_opts = ['--exclude', '.rvm']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "four_ruby #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/four_ruby.gemspec
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{four_ruby}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Andrew Latimer"]
|
12
|
+
s.date = %q{2011-03-23}
|
13
|
+
s.description = %q{A simple Ruby API wrapper for Foursquare.}
|
14
|
+
s.email = %q{andrew@elpasoera.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"config/foursquare_keys.example.yml",
|
28
|
+
"four_ruby.gemspec",
|
29
|
+
"lib/four_ruby.rb",
|
30
|
+
"lib/four_ruby/base.rb",
|
31
|
+
"lib/four_ruby/oauth2.rb",
|
32
|
+
"spec/four_ruby_spec.rb",
|
33
|
+
"spec/spec_helper.rb"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/ahlatimer/four_ruby}
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.5.0}
|
39
|
+
s.summary = %q{A Ruby API wrapper for Foursquare.}
|
40
|
+
s.test_files = [
|
41
|
+
"spec/four_ruby_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 3
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_runtime_dependency(%q<oauth2>, [">= 0"])
|
50
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
51
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
55
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
56
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
58
|
+
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
59
|
+
s.add_runtime_dependency(%q<oauth2>, [">= 0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<oauth2>, [">= 0"])
|
62
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
63
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
64
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
69
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
70
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
71
|
+
s.add_dependency(%q<oauth2>, [">= 0"])
|
72
|
+
end
|
73
|
+
else
|
74
|
+
s.add_dependency(%q<oauth2>, [">= 0"])
|
75
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
76
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
77
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
78
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
79
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
80
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
81
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
82
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
83
|
+
s.add_dependency(%q<hashie>, [">= 0"])
|
84
|
+
s.add_dependency(%q<oauth2>, [">= 0"])
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
data/lib/four_ruby.rb
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'httparty'
|
3
|
+
require 'oauth2'
|
4
|
+
require 'hashie'
|
5
|
+
|
6
|
+
Hash.send :include, Hashie::HashExtensions
|
7
|
+
|
8
|
+
module FourRuby
|
9
|
+
class Base
|
10
|
+
BASE_URL = 'https://api.foursquare.com/v2'
|
11
|
+
ENDPOINTS = [:users, :venues, :tips, :settings, :multi]
|
12
|
+
POST_ACTIONS = [:request, :unfriend, :approve, :deny, :setpings, :marktodo, :flag, :proposeedit, :markdone, :unmark, :add, :set]
|
13
|
+
|
14
|
+
attr_accessor :query
|
15
|
+
|
16
|
+
def initialize(oauth2)
|
17
|
+
@oauth2 = oauth2
|
18
|
+
@query = Hashie::Clash.new
|
19
|
+
@endpoint = nil
|
20
|
+
@result = nil
|
21
|
+
@post = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def method_missing(method_name, params={})
|
25
|
+
if ENDPOINTS.include?(method_name)
|
26
|
+
@endpoint = method_name
|
27
|
+
@query.send(@endpoint, params)
|
28
|
+
elsif @endpoint
|
29
|
+
if @query[@endpoint][method_name] # if that method has already been called, merge the two params hashes
|
30
|
+
@query[@endpoint].merge!( {method_name => params.merge(@query[@endpoint][method_name])})
|
31
|
+
else
|
32
|
+
@post = POST_ACTIONS.include? method_name
|
33
|
+
@query[@endpoint].merge!({ method_name => params })
|
34
|
+
end
|
35
|
+
else
|
36
|
+
raise BadRequest, "You must specify an one of #{ENDPOINTS * ", "}."
|
37
|
+
end
|
38
|
+
@result = nil
|
39
|
+
|
40
|
+
self
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_url
|
44
|
+
return BASE_URL if @endpoint.nil?
|
45
|
+
url = "#{BASE_URL}/#{@endpoint.to_s}#{@query[@endpoint][:id].nil? ? "" : "/" + @query[@endpoint][:id].to_s}"
|
46
|
+
unless @post
|
47
|
+
@query[@endpoint].each do |k,v|
|
48
|
+
next if k == :id
|
49
|
+
url << "/#{k}?"
|
50
|
+
url << stringify_keys(v)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Add a ? if either just the endpoint is being queried or just the id is being used
|
55
|
+
if (@query[@endpoint].size <= 1 && @query[@endpoint][:id]) || (@query[@endpoint].size == 0 && url[-1..url.length] != '?')
|
56
|
+
url << "?"
|
57
|
+
else # otherwise, add a &
|
58
|
+
url << "&" if url[-1..url.length] != "?"
|
59
|
+
end
|
60
|
+
|
61
|
+
# TODO: allow access via an oauth_token
|
62
|
+
url << "client_id=#{@oauth2.id}&client_secret=#{@oauth2.secret}"
|
63
|
+
url = URI.escape(url)
|
64
|
+
url
|
65
|
+
end
|
66
|
+
|
67
|
+
def [](i)
|
68
|
+
self.to_json[i]
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_json
|
72
|
+
return {} if @query.blank?
|
73
|
+
@result ||= send
|
74
|
+
end
|
75
|
+
|
76
|
+
def send
|
77
|
+
parse_response(@oauth2.get(self.to_url))
|
78
|
+
end
|
79
|
+
|
80
|
+
def parse_response(response)
|
81
|
+
raise_errors(response)
|
82
|
+
Crack::JSON.parse(response.body)
|
83
|
+
end
|
84
|
+
|
85
|
+
def clear
|
86
|
+
@query = Hashie::Clash.new
|
87
|
+
@endpoint = nil
|
88
|
+
@result = nil
|
89
|
+
@post = false
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def stringify_keys(h)
|
95
|
+
result = ""
|
96
|
+
return unless h.is_a? Hash
|
97
|
+
h.each do |k,v|
|
98
|
+
result += "#{k}=#{v}&"
|
99
|
+
end
|
100
|
+
result.chomp("&")
|
101
|
+
end
|
102
|
+
|
103
|
+
def raise_errors(response)
|
104
|
+
message = "(#{response.code}): #{response.message} - #{response.inspect} - #{response.body}"
|
105
|
+
|
106
|
+
case response.code.to_i
|
107
|
+
when 400
|
108
|
+
raise BadRequest, message
|
109
|
+
when 401
|
110
|
+
raise Unauthorized, message
|
111
|
+
when 403
|
112
|
+
raise General, message
|
113
|
+
when 404
|
114
|
+
raise NotFound, message
|
115
|
+
when 500
|
116
|
+
raise InternalError, "Foursquare had an internal error. Please let them know in the group.\n#{message}"
|
117
|
+
when 502..503
|
118
|
+
raise Unavailable, message
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
class BadRequest < StandardError; end
|
125
|
+
class Unauthorized < StandardError; end
|
126
|
+
class General < StandardError; end
|
127
|
+
class Unavailable < StandardError; end
|
128
|
+
class InternalError < StandardError; end
|
129
|
+
class NotFound < StandardError; end
|
130
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'hashie'
|
3
|
+
require 'httparty'
|
4
|
+
require 'oauth2'
|
5
|
+
|
6
|
+
Hash.send :include, Hashie::HashExtensions
|
7
|
+
|
8
|
+
module FourRuby
|
9
|
+
class OAuth2
|
10
|
+
attr_accessor :client, :id, :secret
|
11
|
+
|
12
|
+
def initialize(id, secret=nil, options={})
|
13
|
+
if secret
|
14
|
+
@id = id
|
15
|
+
@secret = secret
|
16
|
+
else
|
17
|
+
require 'yaml'
|
18
|
+
yml = YAML::load(File.open(id))
|
19
|
+
raise StandardError, "Foursquare config file does not exist" if yml['foursquare'].nil?
|
20
|
+
@id = yml['foursquare']['client_id']
|
21
|
+
@secret = yml['foursquare']['client_secret']
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def client
|
26
|
+
return @client if @client
|
27
|
+
::OAuth2::Client.new(@id, @secret, :site => 'https://graph.facebook.com')
|
28
|
+
end
|
29
|
+
|
30
|
+
def access_token(code, options={})
|
31
|
+
@access_token ||= client.get_access_token(code, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def authorize_url(redirect_uri)
|
35
|
+
client.web_server.authorize_url(
|
36
|
+
:redirect_uri => redirect_uri,
|
37
|
+
:scope => 'email,offline_access'
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(url)
|
42
|
+
if @access_token
|
43
|
+
@access_token.get(url)
|
44
|
+
else
|
45
|
+
HTTParty.get(url)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def post(url, body)
|
50
|
+
HTTParty.post(url, body)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FourRuby do
|
4
|
+
before(:each) do
|
5
|
+
@four = FourRuby::Base.new(FourRuby::OAuth2.new('config/foursquare_keys.yml'))
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'url generation' do
|
9
|
+
def oauth2_url_pattern
|
10
|
+
"client_id=\\w*&client_secret=\\w*"
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should have a base url of https://api.foursquare.com/v2' do
|
14
|
+
FourRuby::Base::BASE_URL.should == "https://api.foursquare.com/v2"
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'to_url' do
|
18
|
+
it 'should return the BASE_URL when first created' do
|
19
|
+
@four.to_url.should == FourRuby::Base::BASE_URL
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should raise an error when passed an invalid endpoint' do
|
23
|
+
begin
|
24
|
+
@four.bogus_endpoint
|
25
|
+
rescue FourRuby::BadRequest
|
26
|
+
0.should == 0
|
27
|
+
else
|
28
|
+
0.should == 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# This spec is more or less useless, since this isn't a valid query against the 4s api
|
33
|
+
it 'should add an endpoint to the url' do
|
34
|
+
@four.venues
|
35
|
+
@four.to_url.should match /#{FourRuby::Base::BASE_URL}\/venues\?#{oauth2_url_pattern}/
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should add an id to an endpoint' do
|
39
|
+
@four.venues(:id => '123')
|
40
|
+
@four.to_url.should match /#{FourRuby::Base::BASE_URL}\/venues\/123\?#{oauth2_url_pattern}/
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should add an action to an endpoint' do
|
44
|
+
@four.venues.search
|
45
|
+
@four.to_url.should match /#{FourRuby::Base::BASE_URL}\/venues\/search\?#{oauth2_url_pattern}/
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should add parameters' do
|
49
|
+
@four.venues.search(:ll => '123,123')
|
50
|
+
@four.to_url.should match /#{FourRuby::Base::BASE_URL}\/venues\/search\?ll=123,123\&#{oauth2_url_pattern}/
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should allow multiple parameters' do
|
54
|
+
@four.venues.search(:ll => '123,123', :query => 'donuts')
|
55
|
+
@four.to_url.should match /#{FourRuby::Base::BASE_URL}\/venues\/search\?ll=123,123\&query=donuts\&#{oauth2_url_pattern}/
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should allow multiple parameters through multiple calls' do
|
59
|
+
@four.venues.search(:ll => '123,123').search(:query => 'donuts')
|
60
|
+
@four.to_url.should match /#{FourRuby::Base::BASE_URL}\/venues\/search\?ll=123,123\&query=donuts\&#{oauth2_url_pattern}/
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'getting from the API' do
|
66
|
+
before(:each) do
|
67
|
+
@four = FourRuby::Base.new(FourRuby::OAuth2.new('config/foursquare_keys.yml'))
|
68
|
+
@four.venues.search(:ll => '31.794872,-106.290592', :query => 'coffee')
|
69
|
+
end
|
70
|
+
|
71
|
+
after(:each) do
|
72
|
+
@four.clear
|
73
|
+
@four = nil
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should query the api when to_json is called' do
|
77
|
+
@four.to_json.should_not == {}
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'should query the api when [] is called' do
|
81
|
+
@four["response"].should_not == nil
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'posting to the API' do
|
86
|
+
describe 'oauth2 integration' do
|
87
|
+
it 'should integrate with oauth2'
|
88
|
+
|
89
|
+
describe OAuth2 do
|
90
|
+
it 'should allow client_id and client_secret to be passed directly' do
|
91
|
+
o = FourRuby::OAuth2.new('ID', 'SECRET')
|
92
|
+
o.id.should == 'ID'
|
93
|
+
o.secret.should == 'SECRET'
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should get client_id and client_secret from a yaml file, if passed' do
|
97
|
+
o = FourRuby::OAuth2.new('config/foursquare_keys.yml')
|
98
|
+
o.id.should_not be_nil
|
99
|
+
o.secret.should_not be_nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'rspec'
|
12
|
+
require 'shoulda'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
16
|
+
require 'four_ruby'
|
metadata
ADDED
@@ -0,0 +1,239 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: four_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew Latimer
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-23 00:00:00 -06:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :runtime
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 3
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
name: oauth2
|
33
|
+
version_requirements: *id001
|
34
|
+
prerelease: false
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :runtime
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
hash: 3
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
name: hashie
|
47
|
+
version_requirements: *id002
|
48
|
+
prerelease: false
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
type: :runtime
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
hash: 3
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
name: httparty
|
61
|
+
version_requirements: *id003
|
62
|
+
prerelease: false
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
type: :development
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
name: shoulda
|
75
|
+
version_requirements: *id004
|
76
|
+
prerelease: false
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
type: :development
|
79
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ~>
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 23
|
85
|
+
segments:
|
86
|
+
- 1
|
87
|
+
- 0
|
88
|
+
- 0
|
89
|
+
version: 1.0.0
|
90
|
+
name: bundler
|
91
|
+
version_requirements: *id005
|
92
|
+
prerelease: false
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
type: :development
|
95
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
hash: 7
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 5
|
104
|
+
- 2
|
105
|
+
version: 1.5.2
|
106
|
+
name: jeweler
|
107
|
+
version_requirements: *id006
|
108
|
+
prerelease: false
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
type: :development
|
111
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
name: rcov
|
121
|
+
version_requirements: *id007
|
122
|
+
prerelease: false
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
type: :development
|
125
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
126
|
+
none: false
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
hash: 3
|
131
|
+
segments:
|
132
|
+
- 0
|
133
|
+
version: "0"
|
134
|
+
name: rspec
|
135
|
+
version_requirements: *id008
|
136
|
+
prerelease: false
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
type: :runtime
|
139
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
hash: 3
|
145
|
+
segments:
|
146
|
+
- 0
|
147
|
+
version: "0"
|
148
|
+
name: httparty
|
149
|
+
version_requirements: *id009
|
150
|
+
prerelease: false
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
type: :runtime
|
153
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
hash: 3
|
159
|
+
segments:
|
160
|
+
- 0
|
161
|
+
version: "0"
|
162
|
+
name: hashie
|
163
|
+
version_requirements: *id010
|
164
|
+
prerelease: false
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
type: :runtime
|
167
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
hash: 3
|
173
|
+
segments:
|
174
|
+
- 0
|
175
|
+
version: "0"
|
176
|
+
name: oauth2
|
177
|
+
version_requirements: *id011
|
178
|
+
prerelease: false
|
179
|
+
description: A simple Ruby API wrapper for Foursquare.
|
180
|
+
email: andrew@elpasoera.com
|
181
|
+
executables: []
|
182
|
+
|
183
|
+
extensions: []
|
184
|
+
|
185
|
+
extra_rdoc_files:
|
186
|
+
- LICENSE.txt
|
187
|
+
- README.md
|
188
|
+
files:
|
189
|
+
- .document
|
190
|
+
- Gemfile
|
191
|
+
- Gemfile.lock
|
192
|
+
- LICENSE.txt
|
193
|
+
- README.md
|
194
|
+
- Rakefile
|
195
|
+
- VERSION
|
196
|
+
- config/foursquare_keys.example.yml
|
197
|
+
- four_ruby.gemspec
|
198
|
+
- lib/four_ruby.rb
|
199
|
+
- lib/four_ruby/base.rb
|
200
|
+
- lib/four_ruby/oauth2.rb
|
201
|
+
- spec/four_ruby_spec.rb
|
202
|
+
- spec/spec_helper.rb
|
203
|
+
has_rdoc: true
|
204
|
+
homepage: http://github.com/ahlatimer/four_ruby
|
205
|
+
licenses:
|
206
|
+
- MIT
|
207
|
+
post_install_message:
|
208
|
+
rdoc_options: []
|
209
|
+
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
none: false
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
hash: 3
|
218
|
+
segments:
|
219
|
+
- 0
|
220
|
+
version: "0"
|
221
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
222
|
+
none: false
|
223
|
+
requirements:
|
224
|
+
- - ">="
|
225
|
+
- !ruby/object:Gem::Version
|
226
|
+
hash: 3
|
227
|
+
segments:
|
228
|
+
- 0
|
229
|
+
version: "0"
|
230
|
+
requirements: []
|
231
|
+
|
232
|
+
rubyforge_project:
|
233
|
+
rubygems_version: 1.5.0
|
234
|
+
signing_key:
|
235
|
+
specification_version: 3
|
236
|
+
summary: A Ruby API wrapper for Foursquare.
|
237
|
+
test_files:
|
238
|
+
- spec/four_ruby_spec.rb
|
239
|
+
- spec/spec_helper.rb
|