foursquare2 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem 'faraday', '~> 0.5.3'
7
+ gem 'faraday_middleware', '~> 0.3.0'
8
+ gem 'hashie', '~> 1.0.0'
9
+
10
+
11
+
12
+ # Add dependencies to develop your gem here.
13
+ # Include everything needed to run rake, tests, features, etc.
14
+ group :development do
15
+ gem "shoulda", ">= 0"
16
+ gem "bundler", "~> 1.0.0"
17
+ gem "jeweler", "~> 1.5.2"
18
+ gem "rcov", ">= 0"
19
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,33 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.2.4)
5
+ faraday (0.5.5)
6
+ addressable (~> 2.2.4)
7
+ multipart-post (~> 1.1.0)
8
+ rack (>= 1.1.0, < 2)
9
+ faraday_middleware (0.3.2)
10
+ faraday (~> 0.5.4)
11
+ git (1.2.5)
12
+ hashie (1.0.0)
13
+ jeweler (1.5.2)
14
+ bundler (~> 1.0.0)
15
+ git (>= 1.2.5)
16
+ rake
17
+ multipart-post (1.1.0)
18
+ rack (1.2.1)
19
+ rake (0.8.7)
20
+ rcov (0.9.9)
21
+ shoulda (2.11.3)
22
+
23
+ PLATFORMS
24
+ ruby
25
+
26
+ DEPENDENCIES
27
+ bundler (~> 1.0.0)
28
+ faraday (~> 0.5.3)
29
+ faraday_middleware (~> 0.3.0)
30
+ hashie (~> 1.0.0)
31
+ jeweler (~> 1.5.2)
32
+ rcov
33
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Matt Mueller
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/Rakefile ADDED
@@ -0,0 +1,52 @@
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 = "foursquare2"
16
+ gem.homepage = "http://github.com/mattmueller/foursquare2"
17
+ gem.license = "MIT"
18
+ gem.summary = "Foursquare API v2 gem in the spirit of the original foursquare gem"
19
+ gem.description = "Gives access to all endpoints in version 2 of foursquare's API with syntax that will be familiar to those who used the original foursquare gem by Jeremy Welch."
20
+ gem.email = "muellermr@gmail.com"
21
+ gem.authors = ["Matt Mueller"]
22
+ gem.add_runtime_dependency 'faraday', '~> 0.5.3'
23
+ gem.add_runtime_dependency 'faraday_middleware', '~> 0.3.0'
24
+ gem.add_runtime_dependency 'hashie', '~> 1.0.0'
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |test|
37
+ test.libs << 'test'
38
+ test.pattern = 'test/**/test_*.rb'
39
+ test.verbose = true
40
+ end
41
+
42
+ task :default => :test
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "foursquare2 #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/Readme.md ADDED
@@ -0,0 +1,61 @@
1
+ # foursquare2
2
+
3
+ Ruby wrapper for the [foursquare v2 API](http://developer.foursquare.com/docs).
4
+
5
+ ## Installation
6
+
7
+ sudo gem install foursquare2
8
+
9
+ ## Usage
10
+
11
+ ### A Note on Authentication
12
+
13
+ Currently this gem does not handle the oauth2 authentication flow for you, use the [oauth2 gem](https://github.com/intridea/oauth2) to retrieve and store oauth tokens for a user. Obtain your client key/secret for userless access at the [foursquare developer site.](https://foursquare.com/oauth/)
14
+
15
+ ### Instantiate a client (Userless Access)
16
+
17
+ client = Foursquare2::Client.new(:client_key => 'your_key', :client_secret => 'your_secret')
18
+
19
+ ### Instantiate a client (Authenticated User Access)
20
+
21
+ client = Foursquare2::Client.new(:oauth_token => 'user_oauth_token')
22
+
23
+
24
+ ### Examples
25
+
26
+ See [the documentation](http://rubydoc.info/gems/foursquare2) for a list of all supported methods and available options.
27
+
28
+ #### Get information about a user (use 'self' for the authenticated user)
29
+
30
+ client.user(108914)
31
+
32
+ #### Get information about a venue
33
+
34
+ client.venue(5104)
35
+
36
+ #### Search for venues
37
+
38
+ client.search_venues(:ll => '36.142064,-86.816086', :query => 'Starbucks')
39
+
40
+ #### Check-in to a venue as the authenticated user
41
+
42
+ client.checkin(:venueId => "4b2afcaaf964a5205bb324e3", :broadcast => 'public', :ll => '36.142064,-86.816086', :shout => 'zomg coffee!1!')
43
+
44
+ ## Todo
45
+
46
+ * Add test coverage
47
+ * Integrate oauth2 authentication flow
48
+
49
+ ## Contributing to foursquare2
50
+
51
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
52
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
53
+ * Fork the project
54
+ * Start a feature/bugfix branch
55
+ * Commit and push until you are happy with your contribution
56
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
57
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
58
+
59
+ ## Copyright
60
+
61
+ Copyright (c) 2011 Matt Mueller. See LICENSE.txt for further details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.8.0
@@ -0,0 +1,89 @@
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{foursquare2}
8
+ s.version = "0.8.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Matt Mueller"]
12
+ s.date = %q{2011-02-12}
13
+ s.description = %q{Gives access to all endpoints in version 2 of foursquare's API with syntax that will be familiar to those who used the original foursquare gem by Jeremy Welch.}
14
+ s.email = %q{muellermr@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ "Gemfile",
21
+ "Gemfile.lock",
22
+ "LICENSE.txt",
23
+ "Rakefile",
24
+ "Readme.md",
25
+ "VERSION",
26
+ "foursquare2.gemspec",
27
+ "lib/foursquare2.rb",
28
+ "lib/foursquare2/checkins.rb",
29
+ "lib/foursquare2/client.rb",
30
+ "lib/foursquare2/photos.rb",
31
+ "lib/foursquare2/settings.rb",
32
+ "lib/foursquare2/specials.rb",
33
+ "lib/foursquare2/tips.rb",
34
+ "lib/foursquare2/users.rb",
35
+ "lib/foursquare2/venues.rb",
36
+ "test/helper.rb",
37
+ "test/test_foursquare2.rb"
38
+ ]
39
+ s.homepage = %q{http://github.com/mattmueller/foursquare2}
40
+ s.licenses = ["MIT"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.7}
43
+ s.summary = %q{Foursquare API v2 gem in the spirit of the original foursquare gem}
44
+ s.test_files = [
45
+ "test/helper.rb",
46
+ "test/test_foursquare2.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.5.3"])
55
+ s.add_runtime_dependency(%q<faraday_middleware>, ["~> 0.3.0"])
56
+ s.add_runtime_dependency(%q<hashie>, ["~> 1.0.0"])
57
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
60
+ s.add_development_dependency(%q<rcov>, [">= 0"])
61
+ s.add_runtime_dependency(%q<faraday>, ["~> 0.5.3"])
62
+ s.add_runtime_dependency(%q<faraday_middleware>, ["~> 0.3.0"])
63
+ s.add_runtime_dependency(%q<hashie>, ["~> 1.0.0"])
64
+ else
65
+ s.add_dependency(%q<faraday>, ["~> 0.5.3"])
66
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.3.0"])
67
+ s.add_dependency(%q<hashie>, ["~> 1.0.0"])
68
+ s.add_dependency(%q<shoulda>, [">= 0"])
69
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
70
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
71
+ s.add_dependency(%q<rcov>, [">= 0"])
72
+ s.add_dependency(%q<faraday>, ["~> 0.5.3"])
73
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.3.0"])
74
+ s.add_dependency(%q<hashie>, ["~> 1.0.0"])
75
+ end
76
+ else
77
+ s.add_dependency(%q<faraday>, ["~> 0.5.3"])
78
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.3.0"])
79
+ s.add_dependency(%q<hashie>, ["~> 1.0.0"])
80
+ s.add_dependency(%q<shoulda>, [">= 0"])
81
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
82
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
83
+ s.add_dependency(%q<rcov>, [">= 0"])
84
+ s.add_dependency(%q<faraday>, ["~> 0.5.3"])
85
+ s.add_dependency(%q<faraday_middleware>, ["~> 0.3.0"])
86
+ s.add_dependency(%q<hashie>, ["~> 1.0.0"])
87
+ end
88
+ end
89
+
@@ -0,0 +1,19 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+
4
+ directory = File.expand_path(File.dirname(__FILE__))
5
+
6
+ module Foursquare2
7
+ class << self
8
+ end
9
+
10
+ require 'foursquare2/users'
11
+ require 'foursquare2/specials'
12
+ require 'foursquare2/settings'
13
+ require 'foursquare2/photos'
14
+ require 'foursquare2/tips'
15
+ require 'foursquare2/checkins'
16
+ require 'foursquare2/venues'
17
+ require 'foursquare2/client'
18
+
19
+ end
@@ -0,0 +1,74 @@
1
+ module Foursquare2
2
+ module Checkins
3
+
4
+ # Retrive information about a single checkin.
5
+ #
6
+ # @param [String] checkin_id the ID of the checkin.
7
+
8
+ def checkin(checkin_id)
9
+ response = connection.get("checkins/#{checkin_id}")
10
+ return_error_or_body(response, response.body.response.checkin)
11
+ end
12
+
13
+ # Retrive a list of recent checkins from friends.
14
+ #
15
+ # @param [Hash] options
16
+ # @option options String :ll - Latitude and longitude in format LAT,LON
17
+ # @option options String :limit - Maximum results to return (max 100)
18
+ # @option options Integer :afterTimestamp - Seconds after which to look for checkins
19
+
20
+ def recent_checkins(options={})
21
+ response = connection.get do |req|
22
+ req.url "checkins/recent", options
23
+ end
24
+ return_error_or_body(response, response.body.response.recent)
25
+ end
26
+
27
+ # Checkin on behalf of the user.
28
+ #
29
+ # @param [Hash] options
30
+ # @option options String :venueId - Venue for the checkin.
31
+ # @option options String :venue - For venueless checkins (name or other identifier)
32
+ # @option options String :shout - Message to be included with the checkin.
33
+ # @option options String :broadcast - Required, one or more of private,public,facebook,twitter. Comma-separated.
34
+ # @option options String :ll - Latitude and longitude in format LAT,LON
35
+ # @option options Integer :llAcc - Accuracy of the lat/lon in meters.
36
+ # @option options Integer :alt - Altitude in meters
37
+ # @option options Integer :altAcc - Accuracy of the altitude in meters
38
+
39
+ def add_checkin(options={})
40
+ response = connection.post do |req|
41
+ req.url "checkins/add", options
42
+ end
43
+ return_error_or_body(response, response.body.response.checkin)
44
+ end
45
+
46
+ # Add a comment to a checkin.
47
+ #
48
+ # @param [String] checkin_id the ID of the checkin.
49
+ # @param [Hash] options
50
+ # @option options String :text - Text of the comment to add, 200 character max.
51
+
52
+ def add_checkin_comment(checkin_id, options={})
53
+ response = connection.post do |req|
54
+ req.url "checkins/#{checkin_id}/addcomment", options
55
+ end
56
+ return_error_or_body(response, response.body.response)
57
+ end
58
+
59
+ # Delete a checkin's comment
60
+ #
61
+ # @param [String] checkin_id - The ID of the checkin
62
+ # @param [Hash] options
63
+ # @option options String :commentId - ID of the comment to be deleted.
64
+
65
+ def delete_checkin_comment(checkin_id, options={})
66
+ response = connection.post do |req|
67
+ req.url "checkins/#{checkin_id}/deletecomment", options
68
+ end
69
+ return_error_or_body(response, response.body.response)
70
+ end
71
+
72
+ end
73
+ end
74
+
@@ -0,0 +1,71 @@
1
+ require 'forwardable'
2
+
3
+ module Foursquare2
4
+ class Client
5
+ extend Forwardable
6
+
7
+ include Venues
8
+ include Checkins
9
+ include Tips
10
+ include Photos
11
+ include Settings
12
+ include Specials
13
+ include Users
14
+
15
+
16
+ #Initialize the client class that will be used for all foursquare API requests. Note that either a valid user oauth token OR a valid client_id + secret is required.
17
+ #
18
+ #Certain requests will require an oauth token. See http://developer.foursquare.com/docs/index_docs.html for the full list.
19
+ #
20
+ # @param [Hash] options
21
+ # @option options String :client_id Your foursquare app's client_id
22
+ # @option options String :client_secret Your foursquare app's client_secret
23
+ # @option options String :oauth_token A valid oauth token for a user (or the 'secret' value from api v1)
24
+
25
+ def initialize(options={})
26
+ @client_id = options[:client_id]
27
+ @client_secret = options[:client_secret]
28
+ @oauth_token = options[:oauth_token]
29
+ end
30
+
31
+
32
+ # Sets up the connection to be used for all requests based on options passed during initialization.
33
+
34
+ def connection
35
+ params = {}
36
+ params[:client_id] = @client_id if @client_id
37
+ params[:client_secret] = @client_secret if @client_secret
38
+ params[:oauth_token] = @oauth_token if @oauth_token
39
+ @connection ||= Faraday::Connection.new(:url => api_url, :params => params, :headers => default_headers) do |builder|
40
+ builder.adapter Faraday.default_adapter
41
+ builder.use Faraday::Response::ParseJson
42
+ builder.use Faraday::Response::Mashify
43
+ end
44
+ end
45
+
46
+ # Base URL for api requests.
47
+
48
+ def api_url
49
+ "https://api.foursquare.com/v2"
50
+ end
51
+
52
+ # Helper method to return errors or desired response data as appropriate.
53
+ #
54
+ # Added just for convenience to avoid having to traverse farther down the response just to get to returned data.
55
+
56
+ def return_error_or_body(response, response_body)
57
+ response.body.meta.code == 200 ? response_body : response.body
58
+ end
59
+
60
+ private
61
+
62
+
63
+ def default_headers
64
+ headers = {
65
+ :accept => 'application/json',
66
+ :user_agent => 'Ruby gem'
67
+ }
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ module Foursquare2
2
+ module Photos
3
+
4
+ # Retrive a photo
5
+ #
6
+ # @params [String] photo_id - The ID of the photo
7
+
8
+ def photo(photo_id)
9
+ response = connection.get("photos/#{photo_id}")
10
+ return_error_or_body(response, response.body.response.photo)
11
+ end
12
+
13
+ end
14
+ end
15
+
@@ -0,0 +1,34 @@
1
+ module Foursquare2
2
+ module Settings
3
+
4
+ # Retrive all settings for the authenticated user.
5
+
6
+ def settings
7
+ response = connection.get("settings/all")
8
+ return_error_or_body(response, response.body.response.settings)
9
+ end
10
+
11
+ # Retrieve a single setting for the authenticated user.
12
+ #
13
+ # @param [String] setting - The name of the setting to retrieve, one of sendtotwitter, sendtofacebook, pings.
14
+
15
+ def setting(setting)
16
+ response = connection.get("settings/setting")
17
+ return_error_or_body(response, response.body.response)
18
+ end
19
+
20
+ # Update a single setting for the authenticated user.
21
+ #
22
+ # @param [String] setting - The name of the setting to update, one of sendtotwitter, sendtofacebook, pings.
23
+ # @param [String] value - One of '1','0'
24
+
25
+ def update_setting(setting,value)
26
+ response = connection.post do |req|
27
+ req.url "settings/#{setting}/set", {:value => value}
28
+ end
29
+ return_error_or_body(response, response.body.response)
30
+ end
31
+
32
+ end
33
+ end
34
+
@@ -0,0 +1,31 @@
1
+ module Foursquare2
2
+ module Specials
3
+
4
+ # Retrieve information about a special
5
+ #
6
+ # param [String] special_id The ID of the special
7
+
8
+ def special(special_id)
9
+ response = connection.get("specials/#{special_id}")
10
+ return_error_or_body(response, response.body.response.special)
11
+ end
12
+
13
+ # Search for specials
14
+ #
15
+ # @param [Hash] options
16
+ # @option options String :ll - Latitude and longitude in format LAT,LON
17
+ # @option options Integer :llAcc - Accuracy of the lat/lon in meters.
18
+ # @option options Integer :alt - Altitude in meters
19
+ # @option options Integer :altAcc - Accuracy of the altitude in meters
20
+ # @option options Integer :limit - The limit of results to return.
21
+
22
+ def search_specials(options={})
23
+ response = connection.get do |req|
24
+ req.url "specials/search", options
25
+ end
26
+ return_error_or_body(response, response.body.response.specials.items)
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,77 @@
1
+ module Foursquare2
2
+ module Tips
3
+
4
+ # Retrieve information about a tip.
5
+ #
6
+ # param [String] tip_id - The id of the tip to retrieve.
7
+
8
+ def tip(tip_id)
9
+ response = connection.get("tips/#{tip_id}")
10
+ return_error_or_body(response, response.body.response.tip)
11
+ end
12
+
13
+ # Search for tips.
14
+ #
15
+ # @param [Hash] options
16
+ # @option options String :ll - Latitude and longitude in format LAT,LON
17
+ # @option options Integer :limit - The limit of results to return.
18
+ # @option options Integer :offset - Used to page through results.
19
+ # @option options String :filter - Set to 'friends' to limit tips to those from friends.
20
+ # @option options String :query - Only find tips matching this term.
21
+
22
+ def search_tips(options={})
23
+ response = connection.get do |req|
24
+ req.url "tips/search", options
25
+ end
26
+ return_error_or_body(response, response.body.response.tips)
27
+ end
28
+
29
+ # Add a tip
30
+ #
31
+ # @param [Hash] options
32
+ # @option options String :venueId - Required, which venue to add the tip to.
33
+ # @option options String :text - The text of the tip.
34
+ # @option options String :url - Optionally associated url.
35
+
36
+ def add_tip(options={})
37
+ response = connection.post do |req|
38
+ req.url "tips/add", options
39
+ end
40
+ return_error_or_body(response, response.body.response.tip)
41
+ end
42
+
43
+ # Mark a tip todo for the authenticated user.
44
+ #
45
+ # param [String] tip_id - The id of the tip to mark.
46
+
47
+ def mark_tip_todo(tip_id)
48
+ response = connection.post do |req|
49
+ req.url "tips/#{tip_id}/marktodo"
50
+ end
51
+ return_error_or_body(response, response.body.response)
52
+ end
53
+
54
+ # Mark a tip done for the authenticated user.
55
+ #
56
+ # param [String] tip_id - The id of the tip to mark.
57
+
58
+ def mark_tip_done(tip_id)
59
+ response = connection.post do |req|
60
+ req.url "tips/#{tip_id}/markdone"
61
+ end
62
+ return_error_or_body(response, response.body.response)
63
+ end
64
+
65
+ # Unmark a tip todo for the authenticated user.
66
+ #
67
+ # param [String] tip_id - The id of the tip to unmark.
68
+
69
+ def unmark_tip(tip_id)
70
+ response = connection.post do |req|
71
+ req.url "tips/#{tip_id}/unmark"
72
+ end
73
+ return_error_or_body(response, response.body.response)
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,175 @@
1
+ module Foursquare2
2
+ module Users
3
+
4
+ # Get information about a user
5
+ #
6
+ # @param [Integer] user_id - User to get information for.
7
+
8
+ def user(user_id)
9
+ response = connection.get("users/#{user_id}")
10
+ return_error_or_body(response, response.body.response.user)
11
+ end
12
+
13
+ # Search for users
14
+ # @param [Hash] options
15
+ # @option options String :phone - Match on phone number
16
+ # @option options String :email - Match on email
17
+ # @option options String :twitter - Match on twitter username
18
+ # @option options String :twitterSource - Friends of this twitter handle that use foursquare.
19
+ # @option options String :fbid - Match on facebook id.
20
+ # @option options String :name - Match on name
21
+
22
+ def search_users(options={})
23
+ response = connection.get do |req|
24
+ req.url "users/search", options
25
+ end
26
+ return_error_or_body(response, response.body.response)
27
+ end
28
+
29
+ # Get all pending friend requests for the authenticated user
30
+
31
+ def user_requests
32
+ response = connection.get("users/requests")
33
+ return_error_or_body(response, response.body.response.requests)
34
+ end
35
+
36
+ # Get all badges for a given user.
37
+ #
38
+ # @param [String] user_id - The user to retrieve badges for.
39
+
40
+ def user_badges(user_id)
41
+ response = connection.get("users/#{user_id}/badges")
42
+ return_error_or_body(response, response.body.response.sets)
43
+ end
44
+
45
+ # Get checkins for the authenticated user
46
+ # @param [Hash] options
47
+ # @option options Integer :limit
48
+ # @option options Integer :offest - For paging through results
49
+ # @option options Integer :afterTimestamp - Get all checkins after this epoch time.
50
+ # @option options Integer :beforeTimestamp - Get all checkins before this epoch time.
51
+
52
+ def user_checkins(options={})
53
+ response = connection.get do |req|
54
+ req.url "users/self/checkins", options
55
+ end
56
+ return_error_or_body(response, response.body.response.checkins)
57
+ end
58
+
59
+ # Get all friends for a given user.
60
+ #
61
+ # @param [String] user_id - The user to retrieve friends for.
62
+ # @param [Hash] options
63
+ # @option options Integer :limit
64
+ # @option options Integer :offest - For paging through results
65
+
66
+ def user_friends(user_id, options={})
67
+ response = connection.get do |req|
68
+ req.url "users/#{user_id}/friends", options
69
+ end
70
+ return_error_or_body(response, response.body.response.friends)
71
+ end
72
+
73
+ # Get all tips for a given user.
74
+ #
75
+ # @param [String] user_id - The user to retrieve friends for.
76
+ # @param [Hash] options
77
+ # @option options Integer :limit
78
+ # @option options Integer :offest - For paging through results
79
+ # @option options String :sort - One of recent, nearby, popular
80
+ # @option options String :ll - Latitude and longitude in format LAT,LON - required for nearby sort option.
81
+
82
+ def user_tips(user_id, options={})
83
+ response = connection.get do |req|
84
+ req.url "users/#{user_id}/tips", options
85
+ end
86
+ return_error_or_body(response, response.body.response.tips)
87
+ end
88
+
89
+ # Get all todos for a given user.
90
+ #
91
+ # @param [String] user_id - The user to retrieve friends for.
92
+ # @param [Hash] options
93
+ # @option options String :sort - One of recent, nearby, popular
94
+ # @option options String :ll - Latitude and longitude in format LAT,LON - required for nearby sort option.
95
+
96
+
97
+ def user_todos(user_id, options={})
98
+ response = connection.get do |req|
99
+ req.url "users/#{user_id}/todos", options
100
+ end
101
+ return_error_or_body(response, response.body.response.todos)
102
+ end
103
+
104
+ # Get the venue history for the authenticated user.
105
+ #
106
+ # @param [Hash] options
107
+ # @option options Integer :afterTimestamp - Get all venues after this epoch time.
108
+ # @option options Integer :beforeTimestamp - Get all venues before this epoch time.
109
+
110
+
111
+ def user_venue_history(options={})
112
+ response = connection.get do |req|
113
+ req.url "users/self/venuehistory", options
114
+ end
115
+ return_error_or_body(response, response.body.response.venues)
116
+ end
117
+
118
+ # Request friendship with a user
119
+ #
120
+ # @param [String] user_id - The user to request friendship with.
121
+
122
+ def user_friend_request(user_id)
123
+ response = connection.post do |req|
124
+ req.url "users/#{user_id}/request"
125
+ end
126
+ return_error_or_body(response, response.body.response)
127
+ end
128
+
129
+ # Unfriend a user
130
+ #
131
+ # @param [String] user_id - The user to unfriend.
132
+
133
+ def user_unfriend(user_id)
134
+ response = connection.post do |req|
135
+ req.url "users/#{user_id}/unfriend"
136
+ end
137
+ return_error_or_body(response, response.body.response)
138
+ end
139
+
140
+ # Approve friendship with a user.
141
+ #
142
+ # @param [String] user_id - The user to approve friendship with.
143
+
144
+ def user_approve_friend(user_id)
145
+ response = connection.post do |req|
146
+ req.url "users/#{user_id}/approve"
147
+ end
148
+ return_error_or_body(response, response.body.response)
149
+ end
150
+
151
+ # Deny friendship with a user.
152
+ #
153
+ # @param [String] user_id - The user to deny friendship with.
154
+
155
+ def user_deny_friend(user_id)
156
+ response = connection.post do |req|
157
+ req.url "users/#{user_id}/deny"
158
+ end
159
+ return_error_or_body(response, response.body.response)
160
+ end
161
+
162
+ # Set pings for a friend
163
+ #
164
+ # @param [String] user_id - The user to set pings for
165
+ # @param [String] value - The value of ping setting for this friend, either true or false.
166
+
167
+ def user_set_friend_pings(user_id, value)
168
+ response = connection.post do |req|
169
+ req.url "users/#{user_id}/setpings", value
170
+ end
171
+ return_error_or_body(response, response.body.response)
172
+ end
173
+
174
+ end
175
+ end
@@ -0,0 +1,103 @@
1
+ module Foursquare2
2
+ module Venues
3
+
4
+ # Retrieve information about a venue
5
+ #
6
+ # param [String] venue_id The ID of the venue
7
+
8
+ def venue(venue_id)
9
+ response = connection.get("venues/#{venue_id}")
10
+ return_error_or_body(response, response.body.response.venue)
11
+ end
12
+
13
+ # Search for venues
14
+ #
15
+ # @param [Hash] options
16
+ # @option options String :ll - Latitude and longitude in format LAT,LON
17
+ # @option options Integer :llAcc - Accuracy of the lat/lon in meters.
18
+ # @option options Integer :alt - Altitude in meters
19
+ # @option options Integer :altAcc - Accuracy of the altitude in meters
20
+ # @option options Integer :limit - The limit of results to return.
21
+ # @option options String :intent - One of checkin, match, or specials.
22
+ # @option options String :query - Query to match venues on.
23
+
24
+ def search_venues(options={})
25
+ response = connection.get do |req|
26
+ req.url "venues/search", options
27
+ end
28
+ return_error_or_body(response, response.body.response)
29
+ end
30
+
31
+ # Retrieve information about all venue categories.
32
+
33
+ def venue_categories
34
+ response = connection.get("venues/categories")
35
+ return_error_or_body(response, response.body.response.categories)
36
+ end
37
+
38
+ # Add a venue
39
+ # @param [Hash] options
40
+ # @option options String :name - Name of the venue (required)
41
+ # @option options String :address
42
+ # @option options String :crossStreet
43
+ # @option options String :city
44
+ # @option options String :state
45
+ # @option options String :zip
46
+ # @option options String :phone
47
+ # @option options String :ll - Latitude and longitude in format LAT,LON
48
+ # @option options String :primaryCategoryId - Main category for the venue, must be in the list of venue categories.
49
+
50
+ def add_venue(options={})
51
+ response = connection.post do |req|
52
+ req.url "venues/add", options
53
+ end
54
+ return_error_or_body(response, response.body.response.venue)
55
+ end
56
+
57
+ # Mark a venue as todo for the authenticated user
58
+ #
59
+ # @param [String] venue_id - Venue id to mark todo, required.
60
+ # @param [Hash] options
61
+ # @option options String :text - Text for the tip/todo
62
+
63
+ def mark_venue_todo(venue_id, options={})
64
+ response = connection.post do |req|
65
+ req.url "venues/#{venue_id}/marktodo", options
66
+ end
67
+ return_error_or_body(response, response.body.response)
68
+ end
69
+
70
+ # Flag a venue as having a problem
71
+ #
72
+ # @param [String] venue_id - Venue id to flag, required.
73
+ # @param [Hash] options
74
+ # @option options String :problem - Reason for flag, one of mislocated,closed, or duplicate. Required.
75
+
76
+ def flag_venue(venue_id, options={})
77
+ response = connection.post do |req|
78
+ req.url "venues/#{venue_id}/flag", options
79
+ end
80
+ return_error_or_body(response, response.body.response)
81
+ end
82
+
83
+ # Propose a venue edit
84
+ # @param [String] venue_id - Venue id to propose edit for, required.
85
+ # @param [Hash] options
86
+ # @option options String :name - Name of the venue (required)
87
+ # @option options String :address
88
+ # @option options String :crossStreet
89
+ # @option options String :city
90
+ # @option options String :state
91
+ # @option options String :zip
92
+ # @option options String :phone
93
+ # @option options String :ll - Latitude and longitude in format LAT,LON
94
+ # @option options String :primaryCategoryId - Main category for the venue, must be in the list of venue categories.
95
+
96
+ def propose_venue_edit(venue_id, options={})
97
+ response = connection.post do |req|
98
+ req.url "venues/#{venue_id}/proposeedit", options
99
+ end
100
+ return_error_or_body(response, response.body.response)
101
+ end
102
+ end
103
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
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 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'foursquare2'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestFoursquare2 < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,241 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: foursquare2
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
+ platform: ruby
12
+ authors:
13
+ - Matt Mueller
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-12 00:00:00 -06:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ hash: 13
28
+ segments:
29
+ - 0
30
+ - 5
31
+ - 3
32
+ version: 0.5.3
33
+ requirement: *id001
34
+ prerelease: false
35
+ type: :runtime
36
+ name: faraday
37
+ - !ruby/object:Gem::Dependency
38
+ version_requirements: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 19
44
+ segments:
45
+ - 0
46
+ - 3
47
+ - 0
48
+ version: 0.3.0
49
+ requirement: *id002
50
+ prerelease: false
51
+ type: :runtime
52
+ name: faraday_middleware
53
+ - !ruby/object:Gem::Dependency
54
+ version_requirements: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 23
60
+ segments:
61
+ - 1
62
+ - 0
63
+ - 0
64
+ version: 1.0.0
65
+ requirement: *id003
66
+ prerelease: false
67
+ type: :runtime
68
+ name: hashie
69
+ - !ruby/object:Gem::Dependency
70
+ version_requirements: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirement: *id004
80
+ prerelease: false
81
+ type: :development
82
+ name: shoulda
83
+ - !ruby/object:Gem::Dependency
84
+ version_requirements: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ hash: 23
90
+ segments:
91
+ - 1
92
+ - 0
93
+ - 0
94
+ version: 1.0.0
95
+ requirement: *id005
96
+ prerelease: false
97
+ type: :development
98
+ name: bundler
99
+ - !ruby/object:Gem::Dependency
100
+ version_requirements: &id006 !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ hash: 7
106
+ segments:
107
+ - 1
108
+ - 5
109
+ - 2
110
+ version: 1.5.2
111
+ requirement: *id006
112
+ prerelease: false
113
+ type: :development
114
+ name: jeweler
115
+ - !ruby/object:Gem::Dependency
116
+ version_requirements: &id007 !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ hash: 3
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ requirement: *id007
126
+ prerelease: false
127
+ type: :development
128
+ name: rcov
129
+ - !ruby/object:Gem::Dependency
130
+ version_requirements: &id008 !ruby/object:Gem::Requirement
131
+ none: false
132
+ requirements:
133
+ - - ~>
134
+ - !ruby/object:Gem::Version
135
+ hash: 13
136
+ segments:
137
+ - 0
138
+ - 5
139
+ - 3
140
+ version: 0.5.3
141
+ requirement: *id008
142
+ prerelease: false
143
+ type: :runtime
144
+ name: faraday
145
+ - !ruby/object:Gem::Dependency
146
+ version_requirements: &id009 !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ~>
150
+ - !ruby/object:Gem::Version
151
+ hash: 19
152
+ segments:
153
+ - 0
154
+ - 3
155
+ - 0
156
+ version: 0.3.0
157
+ requirement: *id009
158
+ prerelease: false
159
+ type: :runtime
160
+ name: faraday_middleware
161
+ - !ruby/object:Gem::Dependency
162
+ version_requirements: &id010 !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ~>
166
+ - !ruby/object:Gem::Version
167
+ hash: 23
168
+ segments:
169
+ - 1
170
+ - 0
171
+ - 0
172
+ version: 1.0.0
173
+ requirement: *id010
174
+ prerelease: false
175
+ type: :runtime
176
+ name: hashie
177
+ description: Gives access to all endpoints in version 2 of foursquare's API with syntax that will be familiar to those who used the original foursquare gem by Jeremy Welch.
178
+ email: muellermr@gmail.com
179
+ executables: []
180
+
181
+ extensions: []
182
+
183
+ extra_rdoc_files:
184
+ - LICENSE.txt
185
+ files:
186
+ - .document
187
+ - Gemfile
188
+ - Gemfile.lock
189
+ - LICENSE.txt
190
+ - Rakefile
191
+ - Readme.md
192
+ - VERSION
193
+ - foursquare2.gemspec
194
+ - lib/foursquare2.rb
195
+ - lib/foursquare2/checkins.rb
196
+ - lib/foursquare2/client.rb
197
+ - lib/foursquare2/photos.rb
198
+ - lib/foursquare2/settings.rb
199
+ - lib/foursquare2/specials.rb
200
+ - lib/foursquare2/tips.rb
201
+ - lib/foursquare2/users.rb
202
+ - lib/foursquare2/venues.rb
203
+ - test/helper.rb
204
+ - test/test_foursquare2.rb
205
+ has_rdoc: true
206
+ homepage: http://github.com/mattmueller/foursquare2
207
+ licenses:
208
+ - MIT
209
+ post_install_message:
210
+ rdoc_options: []
211
+
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ none: false
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ hash: 3
220
+ segments:
221
+ - 0
222
+ version: "0"
223
+ required_rubygems_version: !ruby/object:Gem::Requirement
224
+ none: false
225
+ requirements:
226
+ - - ">="
227
+ - !ruby/object:Gem::Version
228
+ hash: 3
229
+ segments:
230
+ - 0
231
+ version: "0"
232
+ requirements: []
233
+
234
+ rubyforge_project:
235
+ rubygems_version: 1.3.7
236
+ signing_key:
237
+ specification_version: 3
238
+ summary: Foursquare API v2 gem in the spirit of the original foursquare gem
239
+ test_files:
240
+ - test/helper.rb
241
+ - test/test_foursquare2.rb