foursquared 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/.gitignore +10 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +19 -0
  4. data/Guardfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +30 -0
  7. data/Rakefile +30 -0
  8. data/foursquared.gemspec +34 -0
  9. data/lib/core_ext/symbol.rb +7 -0
  10. data/lib/foursquared/badges.rb +12 -0
  11. data/lib/foursquared/checkins.rb +89 -0
  12. data/lib/foursquared/client.rb +58 -0
  13. data/lib/foursquared/error.rb +17 -0
  14. data/lib/foursquared/events.rb +18 -0
  15. data/lib/foursquared/lists.rb +97 -0
  16. data/lib/foursquared/oauth/client.rb +37 -0
  17. data/lib/foursquared/pages.rb +49 -0
  18. data/lib/foursquared/photos.rb +34 -0
  19. data/lib/foursquared/response/badge.rb +87 -0
  20. data/lib/foursquared/response/badge_group.rb +42 -0
  21. data/lib/foursquared/response/category.rb +53 -0
  22. data/lib/foursquared/response/checkin.rb +180 -0
  23. data/lib/foursquared/response/event.rb +52 -0
  24. data/lib/foursquared/response/list.rb +199 -0
  25. data/lib/foursquared/response/list_item.rb +63 -0
  26. data/lib/foursquared/response/photo.rb +102 -0
  27. data/lib/foursquared/response/special.rb +131 -0
  28. data/lib/foursquared/response/tip.rb +134 -0
  29. data/lib/foursquared/response/user.rb +246 -0
  30. data/lib/foursquared/response/venue.rb +252 -0
  31. data/lib/foursquared/settings.rb +28 -0
  32. data/lib/foursquared/specials.rb +25 -0
  33. data/lib/foursquared/tips.rb +113 -0
  34. data/lib/foursquared/users.rb +206 -0
  35. data/lib/foursquared/venues.rb +217 -0
  36. data/lib/foursquared/version.rb +4 -0
  37. data/lib/foursquared.rb +47 -0
  38. data/spec/foursquared/badges_spec.rb +82 -0
  39. data/spec/foursquared/checkins_spec.rb +0 -0
  40. data/spec/foursquared/events_spec.rb +50 -0
  41. data/spec/foursquared/oauth/client_spec.rb +24 -0
  42. data/spec/foursquared/pages_spec.rb +42 -0
  43. data/spec/foursquared/photos_spec.rb +41 -0
  44. data/spec/foursquared/response/badge_spec.rb +40 -0
  45. data/spec/foursquared/response/category_spec.rb +48 -0
  46. data/spec/foursquared/response/checkin_spec.rb +100 -0
  47. data/spec/foursquared/response/event_category_spec.rb +48 -0
  48. data/spec/foursquared/response/event_spec.rb +60 -0
  49. data/spec/foursquared/response/list_spec.rb +56 -0
  50. data/spec/foursquared/response/photo_spec.rb +70 -0
  51. data/spec/foursquared/response/special_spec.rb +0 -0
  52. data/spec/foursquared/response/user_spec.rb +124 -0
  53. data/spec/foursquared/response/venue_spec.rb +83 -0
  54. data/spec/foursquared/specials_spec.rb +4 -0
  55. data/spec/foursquared/users_spec.rb +241 -0
  56. data/spec/spec_helper.rb +27 -0
  57. metadata +344 -0
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ vendor/bundle/
2
+ .bundle/
3
+ coverage/
4
+ spec/reports
5
+ *.log
6
+ .yardoc
7
+ *.gem
8
+ yardoc/
9
+ *~
10
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format doc
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source :rubygems
2
+
3
+
4
+ group :osx do
5
+ gem "growl"
6
+ end
7
+
8
+ group :linux do
9
+ gem "rb-inotify"
10
+ gem "libnotify"
11
+ end
12
+
13
+ group :windows do
14
+ gem "wdm", "~> 0.0.3"
15
+ gem "win32console"
16
+ gem "rb-notifu"
17
+ end
18
+
19
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+
2
+ guard 'rspec' do
3
+ watch(%r{^spec/.+_spec\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Rony Varghese
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Foursquared
2
+ [![Build Status](https://travis-ci.org/ronyv89/foursquared.png)](https://travis-ci.org/ronyv89/foursquared)
3
+
4
+ Simple client library for Foursquare API V2 with OAuth2 authentication
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'foursquared'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install foursquared
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
30
+
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require 'rspec/core/rake_task'
2
+ require "rake/tasklib"
3
+ require 'ci/reporter/rake/rspec'
4
+ require 'yard'
5
+ require 'yard/rake/yardoc_task'
6
+ require "bundler/gem_tasks"
7
+
8
+ RSpec::Core::RakeTask.new(:spec => ["ci:setup:rspec"]) do |t|
9
+ t.pattern = 'spec/**/*_spec.rb'
10
+ end
11
+
12
+ task :default => :spec
13
+
14
+ desc "Analyze for code complexity"
15
+ task :metric_abc do
16
+ puts `bundle exec metric_abc \`find lib/ -iname '*.rb'\``
17
+ end
18
+
19
+
20
+
21
+ YARD::Rake::YardocTask.new(:yard) do |y|
22
+ y.options = ["--output-dir", "yardoc"]
23
+ end
24
+
25
+ namespace :yardoc do
26
+ desc "generates yardoc files to yardoc/"
27
+ task :generate => :yard do
28
+ puts "Yardoc files generated at yardoc/"
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'foursquared/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "foursquared"
8
+ gem.platform = Gem::Platform::RUBY
9
+ gem.version = Foursquared::VERSION
10
+ gem.authors = ["Rony Varghese"]
11
+ gem.email = ["ronyv250289@gmail.com"]
12
+ gem.description = "Simple foursquare api client"
13
+ gem.summary = "Simple foursquare api client"
14
+ gem.homepage = "https://github.com/ronyv89/foursquared"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.add_dependency 'httmultiparty'
21
+ gem.add_dependency 'oauth2'
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "rake"
24
+ gem.add_development_dependency "guard"
25
+ gem.add_development_dependency "guard-rspec"
26
+ gem.add_development_dependency "simplecov"
27
+ gem.add_development_dependency "metric_abc"
28
+ gem.add_development_dependency "yard"
29
+ gem.add_development_dependency "ci_reporter"
30
+ gem.add_development_dependency "simplecov-rcov"
31
+ gem.add_development_dependency "rdiscount"
32
+ gem.add_development_dependency "webmock"
33
+ gem.add_development_dependency "rspec_multi_matchers"
34
+ end
@@ -0,0 +1,7 @@
1
+ # Ruby's builtin Symbol class
2
+ class Symbol
3
+ # Convert camel case symbol to snake case symbol
4
+ def to_usym
5
+ to_s.gsub(/(.)([A-Z])/,'\1_\2').downcase.to_sym
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ module Foursquared
2
+ # Badges module
3
+ module Badges
4
+ # Badge details
5
+ # @param [String] badge_id required, The id of the badge
6
+ # @return [Foursquared::Response::Badge]
7
+ def badge badge_id
8
+ response = get("/badges/#{badge_id}")["response"]
9
+ Foursquared::Response::Badge.new(self,response["badge"])
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,89 @@
1
+ # Foursquared module
2
+ module Foursquared
3
+ # Checkins module
4
+ module Checkins
5
+
6
+ # Get details of a checkin.
7
+ # @param [String] checkin_id The ID of the checkin to retrieve additional information for.
8
+ # @param [Hash] options
9
+ # @option options [String] :signature
10
+ # @return [Foursquared::Response::Checkin] A checkin object
11
+ def checkin checkin_id, options={}
12
+ response = get("/checkins/#{checkin_id}",options)["response"]
13
+ @checkin = Foursquared::Response::Checkin.new(self, response["checkin"])
14
+ end
15
+
16
+ # Create a check-in
17
+ # @param [Hash] options
18
+ # @option options [String] :venueId required The venue where the user is checking in.
19
+ # @option options [String] :eventId The event the user is checking in to.
20
+ # @option options [String] :shout A message about your check-in
21
+ # @option options [String] :mentions Semicolon-delimited list of mentions
22
+ # @option options [String] :broadcast Who to broadcast this check-in to
23
+ # @option options [String] :ll Latitude and longitude of the user's location.
24
+ # @option options [String] :llAcc Accuracy of the user's latitude and longitude, in meters
25
+ # @option options [String] :alt Altitude of the user's location, in meters.
26
+ # @option options [String] :altAcc Vertical accuracy of the user's location, in meters.
27
+ # @return [Foursquared::Response::Checkin] A checkin object
28
+ def add_checkin options={}
29
+ response = post("/checkins/add", options)["response"]
30
+ {:checkin => Foursquared::Response::Checkin.new(self, response["checkin"]), :notifications => Foursquared::Response::Notifications.new(self, response["notifications"])}
31
+ end
32
+
33
+ # Recent checkins by friends
34
+ # @param [Hash] options
35
+ # @option options [String] :ll Latitude and longitude of the user's location, so response can include distance
36
+ # @option options [Integer] :limit Number of results to return, up to 100.
37
+ # @option options [Integer] :afterTimestamp Seconds after which to look for checkins
38
+ # @return [Array] An array of checkin objects with user details present
39
+ def recent_checkins options={}
40
+ response = get("/checkins/recent", options)["response"]
41
+ @checkins = response["recent"].collect{|checkin| Foursquared::Response::Checkin.new(self, checkin)}
42
+ end
43
+
44
+ # Users who have liked a checkin
45
+ # @param [String] checkin_id The ID of the checkin to get likes for.
46
+ # @return [Hash] A count and groups of users who like this checkin
47
+ def checkin_likes checkin_id
48
+ response = get("/checkins/#{checkin_id}/likes")["response"]
49
+ @likes = response["likes"]
50
+ @likes.groups.each{|group| group["items"].map!{|item|Foursquared::Response::User.new(self, item)}}
51
+ @likes
52
+ end
53
+
54
+ # Add a comment to a check-in
55
+ # @param [String] checkin_id The ID of the checkin to add a comment to.
56
+ # @param [Hash] options
57
+ # @option options [String] :text The text of the comment, up to 200 characters.
58
+ # @option options [String] :mentions Mentions in your check-in.
59
+ # @return [Hash] The newly-created comment.
60
+ def add_checkin_comment checkin_id, options={}
61
+ response = post("/checkins/#{checkin_id}/addcomment", options)["response"]
62
+ @comment = response["comment"]
63
+ @comment["user"] = Foursquared::Response::User.new(self, @comment["user"])
64
+ @comment
65
+ end
66
+
67
+ # Remove commment from check-in
68
+ # @param [String] checkin_id The ID of the checkin to remove a comment from.
69
+ # @param [Hash] options
70
+ # @option options [String] :commentId
71
+ # @return [Foursquared::Response::Checkin] The checkin, minus this comment.
72
+ def delete_checkin_comment checkin_id, options={}
73
+ response = post("/checkins/#{checkin_id}/deletecomment", options)["response"]
74
+ @checkin = Foursquared::Response::Checkin.new(self, response["checkin"])
75
+ end
76
+
77
+ # Like or unlike a checkin
78
+ # @param [String] checkin_id The ID of the checkin to like
79
+ # @param [Hash] options
80
+ # @option options [Integer] :set If 1, like this checkin. If 0 unlike (un-do a previous like) it. Default value is 1.
81
+ def like_checkin checkin_id, options={}
82
+ response = post("/checkins/#{checkin_id}/like", options)["response"]["likes"]
83
+ response["groups"].each do |group|
84
+ group["items"].map!{|item| Foursquared::Response::User.new(self, item)}
85
+ end
86
+ response
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,58 @@
1
+ require 'httmultiparty'
2
+ # Foursquared module
3
+ module Foursquared
4
+ # The Client class
5
+ class Client
6
+ attr_accessor :access_token
7
+ include HTTMultiParty
8
+ include Users
9
+ include Photos
10
+ include Lists
11
+ include Venues
12
+ include Checkins
13
+ include Badges
14
+ include Events
15
+ include Pages
16
+ base_uri 'https://api.foursquare.com/v2/'
17
+ format :json
18
+
19
+ def initialize credentials={}
20
+
21
+ if credentials[:access_token]
22
+ self.class.default_params :oauth_token => credentials[:access_token]
23
+ elsif credentials[:client_id] and credentials[:client_secret]
24
+ self.class.default_params :client_id => credentials[:client_id]
25
+ self.class.default_params :client_secret => credentials[:client_secret]
26
+ else
27
+ raise "Must provide access_token or client_id and client_secret"
28
+ end
29
+ end
30
+
31
+ # Do a 'get' request
32
+ # @param [String] url the url to get
33
+ # @param [Hash] options Additonal options to be passed
34
+ def get url, options={}
35
+ options.merge!({:v => Time.now.strftime("%Y%m%d")}) unless options[:v]
36
+ response = self.class.get(url, {:query => options}).parsed_response
37
+ if response["meta"]["code"] == 200
38
+ return response
39
+ else
40
+ raise Foursquared::Error.new(response["meta"])
41
+ end
42
+ end
43
+
44
+ # Do a 'post' request
45
+ # @param [String] url the url to post
46
+ # @param [Hash] options Additonal options to be passed
47
+ def post url, options={}
48
+ options.merge!({:v => Time.now.strftime("%Y%m%d")}) unless options[:v]
49
+ response = self.class.post(url, {:body => options}).parsed_response
50
+ if response["meta"]["code"] == 200
51
+ return response
52
+ else
53
+ raise Foursquared::Error.new(response["meta"])
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,17 @@
1
+ module Foursquared
2
+ # Error class
3
+ class Error < StandardError
4
+ attr_reader :code, :type, :detail
5
+ def initialize meta
6
+ @code = meta["code"]
7
+ @detail = meta["errorDetail"]
8
+ @type = meta["errorType"]
9
+ end
10
+
11
+ # Error message to be displayed on encountering Foursquare::Error
12
+ def message
13
+ "#{type}: #{detail} (#{code})"
14
+ end
15
+ alias :to_s :message
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module Foursquared
2
+ # Events module
3
+ module Events
4
+ # Return the event with the give ID
5
+ # @return [Foursquared::Response::Event]
6
+ def event event_id
7
+ response = get("/events/#{event_id}")["response"]
8
+ Foursquared::Response::Event.new(self,response["event"])
9
+ end
10
+
11
+ # Return the available event categories
12
+ # @return [Array] An array of event categories
13
+ def event_categories
14
+ response = get("/events/categories")["response"]
15
+ response["categories"].collect{|category| Foursquared::Response::Category.new(self, category)}
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,97 @@
1
+ module Foursquared
2
+ # Lists module
3
+ module Lists
4
+ # Gives details about a list.
5
+ # @param [String] list_id required, ID for a list
6
+ # @param [Hash] options
7
+ # @option options [Integer] :limit Number of results to return, up to 200.
8
+ # @option options [Integer] :offset The number of results to skip
9
+ # @option options [String] :llBounds Restricts the returned results to the input bounding box.
10
+ # @option options [String] :categoryId Restricts the returned results to venues matching the input category id.
11
+ # @return [Foursquared::Response::List]
12
+ def list list_id, options={}
13
+ response = get("/lists/#{list_id}", options)["response"]
14
+ @list = Foursquared::Response::List.new(self, response["list"])
15
+ end
16
+
17
+ # Add a List
18
+ # @param [Hash] options
19
+ # @option options [String] :name required, The name of the list.
20
+ # @option options [String] :description The description of the list.
21
+ # @option options [Boolean] :collaborative Boolean indicating if this list can be edited by friends.
22
+ # @option options [String] :photoId The id of a photo that should be set as the list photo.
23
+ # @return [Foursquared::Response::List] The added list
24
+ def add_list options={}
25
+ response = post("/lists/add", options)["response"]
26
+ Foursquared::Response::List.new(self, response["list"])
27
+ end
28
+
29
+ # Suggests photos that may be appropriate for a list item.
30
+ # @param [String] list_id required, ID for a list
31
+ # @param [Hash] options
32
+ # @option options [String] :itemId required, The ID of the list item
33
+ # @return [Hash] Groups user and others containing lists (a count and items of photos) of photos uploaded by this user and uploaded by other users.
34
+ def suggest_list_photo list_id, options={}
35
+ @photos = get("/lists/#{list_id}/suggestphoto", options)["response"]["photos"]
36
+ if @photos
37
+ @photos.each_key do |key|
38
+ key["items"] = key["items"].collect{|photo| Foursquared::Response::Photo.new(client, photo)}
39
+ end
40
+ end
41
+ @photos
42
+ end
43
+
44
+ # Suggests venues that may be appropriate for a list.
45
+ # @param [String] list_id required, ID for a list
46
+ # @return [Array] Compact venues that may be appropriate for this list.
47
+ def suggest_list_venues list_id
48
+ @suggested_venues = get("/lists/#{list_id}/suggestvenues")["response"]["suggestedVenues"]
49
+ @suggested_venues.each do |item|
50
+ item["venue"] = Foursquared::Response::Venue.new(self, item["venue"])
51
+ end
52
+ @suggested_venues
53
+ end
54
+
55
+ # Suggests tips that may be appropriate for a list item
56
+ # @param [String] list_id required, ID for a list
57
+ # @param [Hash] options
58
+ # @option options [String] :itemId required, The ID of the list item
59
+ def suggest_list_tip list_id, options={}
60
+ @tips = get("/lists/#{list_id}/suggesttip", options)["response"]["tips"]
61
+ if @tips
62
+ @tips.each_key do |key|
63
+ key["items"].map!{|item| Foursquared::Response::Photo.new(client, item)}
64
+ end
65
+ end
66
+ @tips
67
+ end
68
+
69
+ # Add an Item to a list
70
+ # @param [String] list_id required, ID for a list
71
+ # @param [Hash] options
72
+ # @option options [String] :venueId A venue to add to the list
73
+ # @option options [String] :text If the target is a user-created list, this will create a public tip on the venue. If the target is /userid/todos, the text will be a private note that is only visible to the author.
74
+ # @option options [String] :url If adding a new tip via text, this can associate a url with the tip.
75
+ # @option options [String] :tipId Used to add a tip to a list. Cannot be used in conjunction with the text and url fields.
76
+ # @option options [String] :listId Used in conjuction with itemId, the id for a user created or followed list as well as one of USER_ID/tips, USER_ID/todos, or USER_ID/dones.
77
+ # @option options [String] :itemId Used in conjuction with listId, the id of an item on that list that we wish to copy to this list.
78
+ # @return [Foursquared::Response::ListItem] The newly added list item
79
+ def add_list_item list_id, options={}
80
+ @item = post("/lists/#{list_id}/additem", options)["response"]["item"]
81
+ Foursquared::Response::ListItem.new(client, @item) if @item
82
+ end
83
+
84
+ # Delete an item from the list
85
+ # @param [String] list_id required, ID for a list
86
+ # @param [Hash] options
87
+ # @option options [String] :venueId ID of a venue to be deleted.
88
+ # @option options [String] :itemId ID of the item to delete.
89
+ # @option options [String] :tipId id of a tip to be deleted.
90
+ # @return [Hash] A count and items of list items that were just deleted.
91
+ def delete_list_item list_id, options={}
92
+ @items = client.post("/lists/#{list_id}/deleteitem", options)["response"]["items"]
93
+ @items["items"].map!{|item| Foursquared::Response::ListItem.new(client, item)}
94
+ @list_items
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,37 @@
1
+ require 'oauth2'
2
+ module Foursquared
3
+ # OAuth module
4
+ module OAuth
5
+ # OAuth Client class
6
+ class Client
7
+ attr_accessor :client_id, :client_secret, :oauth_client, :callback_url, :access_token
8
+ def initialize(client_id, client_secret, callback_url, opts={}, &block)
9
+ @client_id = client_id
10
+ @client_secret = client_secret
11
+ @callback_url = callback_url
12
+ ssl = opts.delete(:ssl)
13
+
14
+ @options = {
15
+ :site => 'https://foursquare.com/',
16
+ :authorize_url => '/oauth2/authenticate?response_type=code',
17
+ :token_url => '/oauth2/access_token',
18
+ :parse_json => true}.merge(opts)
19
+ @options[:connection_opts][:ssl] = ssl if ssl
20
+ @oauth_client = OAuth2::Client.new(client_id, client_secret, @options)
21
+ end
22
+
23
+ # Step 1: URL for OAuth2 oauthorizetion of Foursquare
24
+ # @return [String]
25
+ def authorize_url
26
+ oauth_client.auth_code.authorize_url(:redirect_uri => callback_url)
27
+ end
28
+
29
+ # Step 2: Get access token after authorizing user
30
+ # @param [String] code The value extracted from the callback url param 'code'
31
+ def get_access_token code
32
+ token = oauth_client.auth_code.get_token(code, :redirect_uri => callback_url)
33
+ @access_token = token.token
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ module Foursquared
2
+ # Pages module
3
+ module Pages
4
+ # Return the page with the given ID
5
+ # @param [String] page_id ID of the page
6
+ # @return [FOursquared::Response::User]
7
+ def page page_id
8
+ response = get("/pages/#{page_id}")["response"]
9
+ @page = Foursquared::Response::User.new(self, response["user"])
10
+ end
11
+
12
+ # Search Pages
13
+ # @param [Hash] options
14
+ # @option options [String] :name A search term to be applied against page names.
15
+ # @option options [String] :twitter A comma-delimited list of Twitter handles to look for.
16
+ # @option options [String] :fbid A comma-delimited list of Facebook ID's to look for.
17
+ def page_search options={}
18
+ response = get("/pages/search",options)["response"]
19
+ @pages = response.collect{|result| Foursquared::Response::User.new(self, result)}
20
+ end
21
+
22
+ # Returns the page's venues.
23
+ # @param [String] page_id ID of the page
24
+ # @param [Hash] options
25
+ # @option options [String] :ll Not valid with ne or sw. Limits results to venues near this latitude and longitude within an optional radius.
26
+ # @option options [String] :radius Not valid with ne or sw. Limit results to venues within this many meters of the specified ll
27
+ # @option options [String] :sw With ne, limits results to the bounding quadrangle defined by the latitude and longitude given by sw as its south-west corner, and ne as its north-east corner.
28
+ # @option options [String] :ne See sw
29
+ # @option options [Integer] :offset The offset of which venues to return. Defaults to 0.
30
+ # @option options [String] :limit The number of venues to return. Defaults to 20, max of 100.
31
+ # @return [Hash] Count and items of venues
32
+ def page_venues page_id, options={}
33
+ @venues = get("/pages/#{page_id}/venues", options)["response"]["venues"]
34
+ @venues["items"].map!{|item| Foursquared::Response::Venue.new(self, item)}
35
+ @venues
36
+ end
37
+
38
+ # Like or unlike a page
39
+ # @param [String] page_id ID of the page to like or unlike.
40
+ # @param [Hash] options
41
+ # @option options [Integer] :set If 1, like this page. If 0 unlike (un-do a previous like) it. Default value is 1.
42
+ # @return [Foursquared::Response::User]
43
+ def like_page page_id, options={}
44
+ response = post("/pages/#{page_id}/like",options)["response"]
45
+ @page = Foursquared::Response::User.new(self, response["user"])
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,34 @@
1
+ module Foursquared
2
+ # photos module
3
+ module Photos
4
+ # Return the photo with the given ID
5
+ # @param photo_id The id of the photo
6
+ # @return [Foursquared::Response::Photo]
7
+ def photo photo_id
8
+ response = get("/photos/#{photo_id}")["response"]
9
+ @photo = Response::Photo.new(self, response["photo"])
10
+ end
11
+
12
+ # Add a new photo to a checkin, tip, venue, or page update in general.
13
+ # @param [Hash] options
14
+ # @option options [String] :checkinId the ID of a checkin owned by the user.
15
+ # @option options [String] :tipId the ID of a tip owned by the user.
16
+ # @option options [String] :venueId the ID of a venue, provided only when adding a public photo of the venue in general, rather than a photo for a private checkin, tip, or page update.
17
+ # @option options [String] :pageId the ID of a page, provided only when adding a photo that will be in an update for that page
18
+ # @option options [String] :broadcast Whether to broadcast this photo example: twitter,facebook
19
+ # @option options [Integer] :public When the checkinId is also provided this parameter allows for making the photo public and viewable at the venue. 1 or 0
20
+ # @option options [String] :ll Latitude and longitude of the user's location.
21
+ # @option options [String] :llAcc Accuracy of the user's latitude and longitude, in meters.
22
+ # @option options [String] :alt Altitude of the user's location, in meters.
23
+ # @option options [String] :altAcc Vertical accuracy of the user's location, in meters.
24
+ # @option options [String] :postUrl A link for more details about the photo.
25
+ # @option options [String] :postContentId Identifier for the photo post to be used in a native link
26
+ # @option options [String] :postText Text for the photo post, up to 200 characters. A checkinId must also be specified in the request.
27
+ # @return [Foursquared::Response::Photo] The photo that was just created.
28
+ def add_photo options={}
29
+ response = post("/photos/add", options)["response"]
30
+ @photo = Response::Photo.new(self, response["photo"])
31
+ end
32
+
33
+ end
34
+ end