skittles 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +20 -0
- data/README.rdoc +55 -0
- data/lib/skittles.rb +28 -0
- data/lib/skittles/api.rb +23 -0
- data/lib/skittles/client.rb +19 -0
- data/lib/skittles/client/checkin.rb +71 -0
- data/lib/skittles/client/photo.rb +65 -0
- data/lib/skittles/client/setting.rb +36 -0
- data/lib/skittles/client/special.rb +33 -0
- data/lib/skittles/client/tip.rb +79 -0
- data/lib/skittles/client/user.rb +179 -0
- data/lib/skittles/client/venue.rb +186 -0
- data/lib/skittles/configuration.rb +69 -0
- data/lib/skittles/connection.rb +19 -0
- data/lib/skittles/request.rb +52 -0
- data/lib/skittles/version.rb +3 -0
- data/spec/skittles_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +253 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Sticksnleaves LLC.
|
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.rdoc
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
= Skittles
|
2
|
+
|
3
|
+
Foursquare v2 REST API client library for Ruby
|
4
|
+
|
5
|
+
== Documentation
|
6
|
+
|
7
|
+
http://rdoc.info/github/anthonator/skittles/
|
8
|
+
|
9
|
+
== Example
|
10
|
+
|
11
|
+
require 'rubygems'
|
12
|
+
require 'skittles'
|
13
|
+
|
14
|
+
Skittles.configure do |config|
|
15
|
+
config.client_id = '...'
|
16
|
+
config.client_secret = '...'
|
17
|
+
config.access_token = '...'
|
18
|
+
end
|
19
|
+
|
20
|
+
Skittles.venue('211152')
|
21
|
+
|
22
|
+
== Contributing to Skittles
|
23
|
+
|
24
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
25
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
26
|
+
* Fork the project
|
27
|
+
* Start a feature/bugfix branch
|
28
|
+
* Commit and push until you are happy with your contribution
|
29
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
30
|
+
* 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.
|
31
|
+
|
32
|
+
== Copyright
|
33
|
+
|
34
|
+
Copyright (c) 2011 Sticksnleaves LLC.
|
35
|
+
|
36
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
37
|
+
a copy of this software and associated documentation files (the
|
38
|
+
"Software"), to deal in the Software without restriction, including
|
39
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
40
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
41
|
+
permit persons to whom the Software is furnished to do so, subject to
|
42
|
+
the following conditions:
|
43
|
+
|
44
|
+
The above copyright notice and this permission notice shall be
|
45
|
+
included in all copies or substantial portions of the Software.
|
46
|
+
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
48
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
49
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
50
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
51
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
52
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
53
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
54
|
+
|
55
|
+
|
data/lib/skittles.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.expand_path('../skittles/version', __FILE__)
|
2
|
+
require File.expand_path('../skittles/configuration', __FILE__)
|
3
|
+
require File.expand_path('../skittles/api', __FILE__)
|
4
|
+
require File.expand_path('../skittles/client', __FILE__)
|
5
|
+
|
6
|
+
# Adapted from the Ruby Twitter gem.
|
7
|
+
# @see https://github.com/jnunemaker/twitter
|
8
|
+
module Skittles
|
9
|
+
extend Configuration
|
10
|
+
|
11
|
+
# Alias for Skittles::Client.new
|
12
|
+
#
|
13
|
+
# @return {Skittles::Client}
|
14
|
+
def self.client(options = {})
|
15
|
+
Skittles::Client.new(options)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Delegate to Skittles::Client
|
19
|
+
def self.method_missing(method, *args, &block)
|
20
|
+
return super unless client.respond_to?(method)
|
21
|
+
client.send(method, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
# Delegate to Skittles::Client
|
25
|
+
def self.respond_to?(method)
|
26
|
+
return client.respond_to?(method) || super
|
27
|
+
end
|
28
|
+
end
|
data/lib/skittles/api.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../connection', __FILE__)
|
2
|
+
require File.expand_path('../request', __FILE__)
|
3
|
+
|
4
|
+
# Adapted from the Ruby Twitter gem.
|
5
|
+
# @see https://github.com/jnunemaker/twitter
|
6
|
+
module Skittles
|
7
|
+
# @private
|
8
|
+
class API
|
9
|
+
# @private
|
10
|
+
attr_accessor(*Configuration::VALID_OPTIONS_KEYS)
|
11
|
+
|
12
|
+
# Creates a new API
|
13
|
+
def initialize(options = {})
|
14
|
+
options = Skittles.options.merge(options)
|
15
|
+
Configuration::VALID_OPTIONS_KEYS.each do |key|
|
16
|
+
send("#{key}=", options[key])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
include Connection
|
21
|
+
include Request
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Adapted from the Ruby Twitter gem.
|
2
|
+
# @see https://github.com/jnunemaker/twitter
|
3
|
+
module Skittles
|
4
|
+
# Wrapper for the Foursquare v2 REST API
|
5
|
+
#
|
6
|
+
# @note All methods have been separated into modules and follow the same grouping used in {http://developer.foursquare.com/docs/}.
|
7
|
+
# @see http://developer.foursquare.com/docs/index_docs.html
|
8
|
+
class Client < API
|
9
|
+
Dir[File.expand_path('../client/*.rb', __FILE__)].each { |f| require f }
|
10
|
+
|
11
|
+
include Skittles::Client::Venue
|
12
|
+
include Skittles::Client::User
|
13
|
+
include Skittles::Client::Checkin
|
14
|
+
include Skittles::Client::Tip
|
15
|
+
include Skittles::Client::Photo
|
16
|
+
include Skittles::Client::Setting
|
17
|
+
include Skittles::Client::Special
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Skittles
|
2
|
+
class Client
|
3
|
+
# Define methods related to checkins.
|
4
|
+
# @see http://developer.foursquare.com/docs/checkins/checkins.html
|
5
|
+
module Checkin
|
6
|
+
# Allows a user to checkin to a place.
|
7
|
+
#
|
8
|
+
# @param broadcast [String] How much to broadcast this check-in, ranging from private (off-the-grid) to public,faceboook,twitter.
|
9
|
+
# @param options [Hash] A customizable set of options.
|
10
|
+
# @option options [String] venueId The venue where the user is checking in.
|
11
|
+
# @option options [String] venue Name of the venue.
|
12
|
+
# @option options [String] shout A message about a check-in. (140 character max.)
|
13
|
+
# @option options [String] ll Latitude and longitude of the user's location.
|
14
|
+
# @option options [Decimal] llAcc Accuracy of the user's latitude and longitude, in meters.
|
15
|
+
# @option options [Decimal] alt Altitude of the user's location, in meters.
|
16
|
+
# @option options [Decimal] altAcc Vertical accuracy of the user's location, in meters.
|
17
|
+
# @return [Hashie::Mash] A checkin object.
|
18
|
+
# @requires_acting_user Yes
|
19
|
+
# @see http://developer.foursquare.com/docs/checkins/add.html
|
20
|
+
def add_checkin(broadcast = 'private', options = {})
|
21
|
+
post("checkins/add", { :broadcast => broadcast }.merge(options)).checkin
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get details of a checkin.
|
25
|
+
#
|
26
|
+
# @param id [String] The ID of the checkin to retrieve additional information for.
|
27
|
+
# @return [Hashie::Mash] A complete checkin object.
|
28
|
+
# @requires_acting_user Yes
|
29
|
+
# @see http://developer.foursquare.com/docs/checkins/checkins.html
|
30
|
+
def checkin(id)
|
31
|
+
get("checkins/#{id}").checkin
|
32
|
+
end
|
33
|
+
|
34
|
+
# Comment on a check-in.
|
35
|
+
#
|
36
|
+
# @param id [String] The id of the checkin to add a comment to.
|
37
|
+
# @param text [String] The text of the comment, up to 200 characters.
|
38
|
+
# @return [Hashie::Mash] The newly-created comment.
|
39
|
+
# @requires_acting_user Yes
|
40
|
+
# @see http://developer.foursquare.com/docs/checkins/addcomment.html
|
41
|
+
def checkin_addcomment(id, text)
|
42
|
+
post("checkins/#{id}/addcomment", { :text => text }).comment
|
43
|
+
end
|
44
|
+
|
45
|
+
# Remove a comment from a checkin, if the acting user is the author or
|
46
|
+
# the owner of the checkin.
|
47
|
+
#
|
48
|
+
# @param checkin_id [String] The id of the checkin to remove a comment from.
|
49
|
+
# @param comment_id [String] The id of the comment to remove.
|
50
|
+
# @return [Hashie::Mash] The checkin, minus this comment.
|
51
|
+
# @requires_acting_user Yes
|
52
|
+
# @see http://developer.foursquare.com/docs/checkins/deletecomment.html
|
53
|
+
def checkin_deletecomment(checkin_id, comment_id)
|
54
|
+
post("checkins/#{checkin_id}/deletecomment", { :commentId => comment_id }).checkin
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns a list of recent checkins from friends.
|
58
|
+
#
|
59
|
+
# @param ll [String] Latitude and longitude of the user's location, so response can include distance.
|
60
|
+
# @param options [Hash] A customizable set of options.
|
61
|
+
# @option options [Integer] Number of results to return, up to 100.
|
62
|
+
# @option options [Integer] Seconds after which to look for checkins.
|
63
|
+
# @return [Hashie::Mash] An array of checkin objects with user details present.
|
64
|
+
# @requires_acting_user Yes
|
65
|
+
# @see http://developer.foursquare.com/docs/checkins/recent.html
|
66
|
+
def recent_checkins(ll, options = {})
|
67
|
+
get("checkins/recent", { :ll => ll }.merge(options)).recent
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http/post/multipart'
|
3
|
+
|
4
|
+
module Skittles
|
5
|
+
class Client
|
6
|
+
# Define methods related to photos.
|
7
|
+
# @see http://developer.foursquare.com/docs/photos/photos.html
|
8
|
+
module Photo
|
9
|
+
# Get details of a photo.
|
10
|
+
#
|
11
|
+
# @param id [String] The id of the photo to retrieve additional information for.
|
12
|
+
# @return A complete photo object.
|
13
|
+
# @requires_acting_user Yes
|
14
|
+
# @see http://developer.foursquare.com/docs/photos/photos.html
|
15
|
+
def photo(id)
|
16
|
+
get("photos/#{id}").photo
|
17
|
+
end
|
18
|
+
|
19
|
+
# Allows users to add a new photo to a checkin, tip, or a venue in
|
20
|
+
# general.
|
21
|
+
#
|
22
|
+
# @param file [String] Path to the file to upload.
|
23
|
+
# @param options [Hash] A customizable set of options.
|
24
|
+
# @option options [String] checkinId The id of a checkin owned by the user.
|
25
|
+
# @option options [String] tipId The ID of a tip owned by the user.
|
26
|
+
# @option options [String] venueId The ID of a venue, provided only when adding a public photo of the venue in general, rather than a private checkin or tip photo using the parameters above.
|
27
|
+
# @option options [String] broadcast Whether to broadcast this photo to twitter, facebook or both.
|
28
|
+
# @option options [String] ll Latitude and longitude of the user's location.
|
29
|
+
# @option options [Decimal] llAcc Accuracy of the user's latitude and longitude, in meters.
|
30
|
+
# @option options [Decimal] alt Altitude of the user's location, in meters.
|
31
|
+
# @option options [Decimal] altAcc Vertical accuracy of the user's location, in meters.
|
32
|
+
# @return The photo that was just created.
|
33
|
+
# @requires_acting_user Yes
|
34
|
+
# @see http://developer.foursquare.com/docs/photos/add.html
|
35
|
+
def add_photo(file, options = {})
|
36
|
+
resp = nil
|
37
|
+
options.merge!({
|
38
|
+
:file => UploadIO.new(file, 'image/jpeg', 'image.jpg'),
|
39
|
+
:oauth_token => access_token
|
40
|
+
})
|
41
|
+
uri = URI.parse("#{endpoint}/photos/add")
|
42
|
+
File.open(file) do |file|
|
43
|
+
req = Net::HTTP::Post::Multipart.new(uri.path, options)
|
44
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
45
|
+
http.use_ssl = true if uri.scheme == 'https'
|
46
|
+
resp = http.start do |http|
|
47
|
+
http.request(req)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
case resp.code.to_i
|
51
|
+
when 200..299
|
52
|
+
return Hashie::Mash.new(Yajl::Parser.new.parse(resp.body)).response.photo
|
53
|
+
when 401
|
54
|
+
e = OAuth2::AccessDenied.new("Received HTTP 401 during request.")
|
55
|
+
e.response = resp
|
56
|
+
raise e
|
57
|
+
else
|
58
|
+
e = OAuth2::HTTPError.new("Received HTTP #{resp.code} during request.")
|
59
|
+
e.response = resp
|
60
|
+
raise e
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Skittles
|
2
|
+
class Client
|
3
|
+
# Define methods related to settings.
|
4
|
+
# @see http://developer.foursquare.com/docs/settings/settings.html
|
5
|
+
module Setting
|
6
|
+
# Returns all settings of the active user.
|
7
|
+
#
|
8
|
+
# @return [Hashie::Mash] A setting object for the acting user.
|
9
|
+
# @requires_acting_user Yes
|
10
|
+
# @see http://developer.foursquare.com/docs/settings/all.html
|
11
|
+
def all_settings
|
12
|
+
get('settings/all').settings
|
13
|
+
end
|
14
|
+
|
15
|
+
# Change a setting for the given user.
|
16
|
+
#
|
17
|
+
# @param id [String] Name of setting to change, sendToTwitter, sendToFacebook, receivePings, receiveCommentPings.
|
18
|
+
# @param value [Integer] 1 for true, and 0 for false.
|
19
|
+
# @requires_acting_user Yes
|
20
|
+
# @see http://developer.foursquare.com/docs/settings/set.html
|
21
|
+
def set_setting(id, value)
|
22
|
+
post("settings/#{id}/set", { :value => value }).settings
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns a setting for the acting user.
|
26
|
+
#
|
27
|
+
# @param id [String] The name of a setting.
|
28
|
+
# @return [Hashie::Mash] The value for this setting for the acting user.
|
29
|
+
# @requires_acting_user Yes
|
30
|
+
# @see http://developer.foursquare.com/docs/settings/settings.html
|
31
|
+
def setting(id)
|
32
|
+
get("settings/#{id}").value
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Skittles
|
2
|
+
class Client
|
3
|
+
# Define methods related to specials.
|
4
|
+
# @see http://developer.foursquare.com/docs/specials/specials.html
|
5
|
+
module Special
|
6
|
+
# Gives details about a special, including text and unlock rules.
|
7
|
+
#
|
8
|
+
# @param id [String] Id of special to retrieve.
|
9
|
+
# @return [Hashie::Mash] A complete special.
|
10
|
+
# @requires_acting_user No
|
11
|
+
# @see http://developer.foursquare.com/docs/specials/specials.html
|
12
|
+
def special(id)
|
13
|
+
get("specials/#{id}")
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a list of specials near the current location.
|
17
|
+
#
|
18
|
+
# @note This is an experimental API.
|
19
|
+
# @param ll [String] Latitude and longitude to search near.
|
20
|
+
# @param options [Hash] A customizable set of options.
|
21
|
+
# @option options [Decimal] llAcc Accuracy of latitude and longitude, in meters.
|
22
|
+
# @option options [Decimal] alt Altitude of the user's location, in meters.
|
23
|
+
# @option options [Decimal] altAcc Accuracy of the user's altitude, in meters.
|
24
|
+
# @option options [Integer] limit Number of results to return, up to 50.
|
25
|
+
# @return [Hashie::Mash] An array of specials being run at nearby venues.
|
26
|
+
# @requires_acting_user Yes
|
27
|
+
# @see http://developer.foursquare.com/docs/specials/search.html
|
28
|
+
def special_search(ll, options = {})
|
29
|
+
get('specials/search', { :ll => ll }.merge(options))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Skittles
|
2
|
+
class Client
|
3
|
+
# Define methods related to tips.
|
4
|
+
# @see http://developer.foursquare.com/docs/tips/tips.html
|
5
|
+
module Tip
|
6
|
+
# Allows a user to add a new tip at a venue.
|
7
|
+
#
|
8
|
+
# @param id [String] The venue where you want to add this tip.
|
9
|
+
# @param text [String] The text of the tip.
|
10
|
+
# @param options [Hash] A customizable set of options.
|
11
|
+
# @option options [String] url A URL related to this tip.
|
12
|
+
# @return [Hashie::Mash] The newly-added tip.
|
13
|
+
# @requires_acting_user Yes
|
14
|
+
# @see http://developer.foursquare.com/docs/tips/add.html
|
15
|
+
def add_tip(id, text, options = {})
|
16
|
+
post("tips/add", {
|
17
|
+
:venueId => id,
|
18
|
+
:text => text
|
19
|
+
}.merge(options)).tip
|
20
|
+
end
|
21
|
+
|
22
|
+
# Gives details about a tip, including which users (especially friends)
|
23
|
+
# have marked the tip to-do or done.
|
24
|
+
#
|
25
|
+
# @param id [String] Id of tip to retrieve.
|
26
|
+
# @return [Hashie::Mash] A complete tip.
|
27
|
+
# @requires_acting_user No
|
28
|
+
# @see http://developer.foursquare.com/docs/tips/tips.html
|
29
|
+
def tip(id)
|
30
|
+
get("tips/#{id}").tip
|
31
|
+
end
|
32
|
+
|
33
|
+
# Allows the acting user to mark a tip done.
|
34
|
+
#
|
35
|
+
# @param id [String] The tip you want to mark done.
|
36
|
+
# @return [Hashie::Mash] The marked to-do.
|
37
|
+
# @requires_acting_user Yes
|
38
|
+
# @see http://developer.foursquare.com/docs/tips/markdone.html
|
39
|
+
def tip_markdone(id)
|
40
|
+
post("tips/#{id}/markdone").todo
|
41
|
+
end
|
42
|
+
|
43
|
+
# Allows you to mark a tip to-do.
|
44
|
+
#
|
45
|
+
# @param id [String] The tip you want to mark to-do.
|
46
|
+
# @return [Hashie::Mash] The newly-added to-do.
|
47
|
+
# @requires_acting_user Yes
|
48
|
+
# @see http://developer.foursquare.com/docs/tips/marktodo.html
|
49
|
+
def tip_marktodo(id)
|
50
|
+
post("tips/#{id}/marktodo").todo
|
51
|
+
end
|
52
|
+
|
53
|
+
# Returns a list of tips near the area specified.
|
54
|
+
#
|
55
|
+
# @param ll [String] Latitude and longitude of the user's location.
|
56
|
+
# @param options [Hash] A customizable set of options.
|
57
|
+
# @option options [Integer] limit Number of results to return, up to 500.
|
58
|
+
# @option options [Integer] offset Used to page through results.
|
59
|
+
# @option options [String] filter If set to friends, only show nearby tips from friends.
|
60
|
+
# @option options [String] query Only find tips matching the given term, cannot be used in conjunction with friends filter.
|
61
|
+
# @return [Hashie::Mash] An array of tips, each of which contain a user and venue.
|
62
|
+
# @requires_acting_user No
|
63
|
+
# @see http://developer.foursquare.com/docs/tips/search.html
|
64
|
+
def tip_search(ll, options = {})
|
65
|
+
get("tips/search", { :ll => ll }.merge(options)).tips
|
66
|
+
end
|
67
|
+
|
68
|
+
# Allows you to remove a tip from your to-do list or done list.
|
69
|
+
#
|
70
|
+
# @param id [String] The tip you want to unmark.
|
71
|
+
# @return The tip being acted on.
|
72
|
+
# @requires_acting_user No
|
73
|
+
# @see http://developer.foursquare.com/docs/tips/unmark.html
|
74
|
+
def tip_unmark(id)
|
75
|
+
post("tips/#{id}/unmark")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
module Skittles
|
2
|
+
class Client
|
3
|
+
# Define methods related to users.
|
4
|
+
# @see http://developer.foursquare.com/docs/users/users.html
|
5
|
+
module User
|
6
|
+
# Approve a pending friend request from another user.
|
7
|
+
#
|
8
|
+
# @param id [String] The user ID of a pending friend.
|
9
|
+
# @return [Hashie::Mash] A user object for the approved user.
|
10
|
+
# @requires_acting_user Yes
|
11
|
+
# @see http://developer.foursquare.com/docs/users/approve.html
|
12
|
+
def approve_user(id)
|
13
|
+
post("users/#{id}/approve").user
|
14
|
+
end
|
15
|
+
# Returns badges for a given user.
|
16
|
+
#
|
17
|
+
# @param id [String] Id for user to view badges for.
|
18
|
+
# @return [Hashie::Mash] Hierarchical groups of badge ids or, for unlocked badges, badge unlock ids, as they are intended for display.
|
19
|
+
# @return [Hashie::Mash] A map of badge ids or badge unlock ids to a badge.
|
20
|
+
# @requires_acting_user Yes
|
21
|
+
# @see http://developer.foursquare.com/docs/users/badges.html
|
22
|
+
def badges(id)
|
23
|
+
get("users/#{id}/badges")
|
24
|
+
end
|
25
|
+
|
26
|
+
# Returns a history of checkins for the authenticated user.
|
27
|
+
#
|
28
|
+
# @param id [String] For now, only "self" is supported.
|
29
|
+
# @param options [Hash] A customizable set of options.
|
30
|
+
# @option options [Integer] limit Number of results to return, up to 500.
|
31
|
+
# @option options [Integer] offset Used to page through results.
|
32
|
+
# @option options [Integer] afterTimestamp Retrieve the first results to follow these seconds since epoch.
|
33
|
+
# @option options [Integer] beforeTimestamp Retrieve the first results prior to these seconds since epoch.
|
34
|
+
# @return [Hashie::Mash] A count of items in check-ins.
|
35
|
+
# @requires_acting_user Yes
|
36
|
+
# @see http://developer.foursquare.com/docs/users/checkins.html
|
37
|
+
def checkins(id = 'self', options = {})
|
38
|
+
get("users/#{id}/checkins").checkins
|
39
|
+
end
|
40
|
+
|
41
|
+
# Denies a pending friend request from another user.
|
42
|
+
#
|
43
|
+
# @param id [String] The user ID of a pending friend.
|
44
|
+
# @return [Hashie::Mash] A user object for the denied user.
|
45
|
+
# @requires_acting_user Yes
|
46
|
+
# @see http://developer.foursquare.com/docs/users/deny.html
|
47
|
+
def deny_user(id)
|
48
|
+
post("users/#{id}/deny").user
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sends a friend request to another user.
|
52
|
+
#
|
53
|
+
# @param id [String] The user ID to which a request will be sent.
|
54
|
+
# @return [Hashie::Mash] A user object for the pending user.
|
55
|
+
# @requires_acting_user Yes
|
56
|
+
# @see http://developer.foursquare.com/docs/users/request.html
|
57
|
+
def friend_request(id)
|
58
|
+
get("users/#{id}").user
|
59
|
+
end
|
60
|
+
|
61
|
+
# Shows a user the list of users with whom they have a pending friend
|
62
|
+
# request.
|
63
|
+
#
|
64
|
+
# @return [Hashie::Mash] An array of compact user objects.
|
65
|
+
# @requires_acting_user Yes
|
66
|
+
# @see http://developer.foursquare.com/docs/users/requests.html
|
67
|
+
def friend_requests
|
68
|
+
get("users/requests").requests
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns an array of user's friends.
|
72
|
+
#
|
73
|
+
# @param id [String] Identity of the user to get friends of. Pass self to
|
74
|
+
# get friends of the acting user.
|
75
|
+
# @param options [Hash] A customizable set of options.
|
76
|
+
# @option options [Integer] limit Number of results to return, up to 500.
|
77
|
+
# @option options [Integer] offset Used to page through results.
|
78
|
+
# @return [Hashie::Mash] A count and items of compact user objects.
|
79
|
+
# @requires_acting_user Yes
|
80
|
+
# @see http://developer.foursquare.com/docs/users/friends.html
|
81
|
+
def friends(id, options = {})
|
82
|
+
get("users/#{id}/friends").friends
|
83
|
+
end
|
84
|
+
|
85
|
+
# Changes whether the acting user will receive pings (phone
|
86
|
+
# notifications) when the specified user checks in.
|
87
|
+
#
|
88
|
+
# @param id [String] The user ID of a friend.
|
89
|
+
# @param value [Boolean] True of false.
|
90
|
+
# @return [Hashie::Mash] A user object for the user.
|
91
|
+
# @requires_acting_user Yes
|
92
|
+
# @see http://developer.foursquare.com/docs/users/setpings.html
|
93
|
+
def setpings(id, value = false)
|
94
|
+
post("users/#{id}/setpings", { :value => value }).user
|
95
|
+
end
|
96
|
+
|
97
|
+
# Returns todos from a user.
|
98
|
+
#
|
99
|
+
# @param id Identity of the user to get todos for. Pass self to get todos of the acting user.
|
100
|
+
# @param sort One of recent or popular. Nearby requires geolat and geolong to be provided.
|
101
|
+
# @param options [Hash] A customizable set of options.
|
102
|
+
# @option options [String] ll Latitude and longitude of the user's location.
|
103
|
+
# @return [Hashie::Mash] A count and items of todos.
|
104
|
+
# @requires_acting_user Yes
|
105
|
+
# @see http://developer.foursquare.com/docs/users/todos.html
|
106
|
+
def todos(id, sort = 'recent', options = {})
|
107
|
+
get("users/#{id}/todos", { :sort => sort }.merge(options)).todos
|
108
|
+
end
|
109
|
+
|
110
|
+
# Returns profile information for a given user, including selected badges
|
111
|
+
# and mayorships.
|
112
|
+
#
|
113
|
+
# @param id [String] Identity of the user to get details for. Pass self to get details of the acting user.
|
114
|
+
# @return [Hashie::Mash] Profile information for a given user.
|
115
|
+
# @requires_acting_user Yes
|
116
|
+
# @see http://developer.foursquare.com/docs/users/users.html
|
117
|
+
def user(id)
|
118
|
+
get("users/#{id}").user
|
119
|
+
end
|
120
|
+
|
121
|
+
# Cancels any relationship between the acting user and the specified
|
122
|
+
# user.
|
123
|
+
#
|
124
|
+
# @param id [String] Identity of the user to unfriend.
|
125
|
+
# @return [Hashie::Mash] A user.
|
126
|
+
# @requires_acting_user Yes
|
127
|
+
# @see http://developer.foursquare.com/docs/users/unfriend.html
|
128
|
+
def unfriend(id)
|
129
|
+
post("users/#{id}/unfriend").user
|
130
|
+
end
|
131
|
+
|
132
|
+
# Helps a user locate friends.
|
133
|
+
#
|
134
|
+
# @param options [Hash] A customizable set of options.
|
135
|
+
# @option options [String] phone A comma-delimited list of phone numbers to look for.
|
136
|
+
# @option options [String] email A comma-delimited list of email addresses to look for.
|
137
|
+
# @option options [String] twitter A comma-delimited list of Twitter handles to look for.
|
138
|
+
# @option options [String] twitterSource A single Twitter handle. Results will be friends of this user who use Foursquare.
|
139
|
+
# @option options [String] fbid A comma-delimited list of Facebook id's to look for.
|
140
|
+
# @option options [String] name A single string to search for in users' names.
|
141
|
+
# @return [Hashie::Mash] An array of compact user objects with Twitter or Facebook information and friend status.
|
142
|
+
# @requires_acing_user Yes
|
143
|
+
# @see http://developer.foursquare.com/docs/users/search.html
|
144
|
+
def user_search(options = {})
|
145
|
+
get('users/search', options).results
|
146
|
+
end
|
147
|
+
|
148
|
+
# Returns tips from a user.
|
149
|
+
#
|
150
|
+
# @param id [String] Identity of the user to get tips from. Pass self to get tips of the acting user.
|
151
|
+
# @option options [Hash] A customizable set of options.
|
152
|
+
# @option options [String] sort One of recent, nearby, or popular. Nearby requires geolat and geolong to be provided.
|
153
|
+
# @option options [String] ll Latitude and longitude of the user's location.
|
154
|
+
# @option options [String] limit Number of results to return, up to 500.
|
155
|
+
# @option options [String] offset Used to page through results.
|
156
|
+
# @return [Hashie::Mash] A count and items of tips.
|
157
|
+
# @requires_acting_user Yes
|
158
|
+
# @see http://developer.foursquare.com/docs/users/tips.html
|
159
|
+
def user_tips(id, options = {})
|
160
|
+
get("users/#{id}/tips").tips
|
161
|
+
end
|
162
|
+
|
163
|
+
# Returns a list of all venues visited by the specified user, along with
|
164
|
+
# how many visits and when they were last there.
|
165
|
+
#
|
166
|
+
# @note This is an experimental API.
|
167
|
+
# @param id [String] For now, only "self" is supported.
|
168
|
+
# @param options [Hash] A customizable set of options.
|
169
|
+
# @option options [Integer] beforeTimestamp Seconds since epoch.
|
170
|
+
# @option options [Integer] Seconds after epoch.
|
171
|
+
# @return [Hashie::Mash] A count and items of objects containing a beenHere count, lastHereAt timestamp, and venue compact venues.
|
172
|
+
# @requires_acting_user Yes
|
173
|
+
# @see http://developer.foursquare.com/docs/users/venuehistory.html
|
174
|
+
def venuehistory(id = 'self', options = {})
|
175
|
+
get("users/#{id}/venuehistory", options).venues
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
module Skittles
|
2
|
+
class Client
|
3
|
+
# Defines methods related to venues.
|
4
|
+
# @see http://developer.foursquare.com/docs/venues/venues.html
|
5
|
+
module Venue
|
6
|
+
# Adds a new venue.
|
7
|
+
#
|
8
|
+
# All fields are optional, but one of either a valid address or a
|
9
|
+
# geolat/geolong pair must be provided. It is recommended that a
|
10
|
+
# geolat/geolong pair is provided in every case.
|
11
|
+
#
|
12
|
+
# Optionally, a category(primarycategoryid) may be passed in to which
|
13
|
+
# this venue is to be assigned. A full list of categories using the
|
14
|
+
# {http://developer.foursquare.com/docs/venues/categories.html /categories}
|
15
|
+
# method.
|
16
|
+
#
|
17
|
+
# @param name [String] The name of the venue.
|
18
|
+
# @param options [Hash] A customizable set of options.
|
19
|
+
# @option options [String] address The address of the venue.
|
20
|
+
# @option options [String] crossStreen The nearest intersecting street or streets.
|
21
|
+
# @option options [String] city The city name where this venue is.
|
22
|
+
# @option options [String] state The nearest state or province to the venue.
|
23
|
+
# @option options [String] zip The zip or postal code for the venue.
|
24
|
+
# @option options [String] phone The phone number of the venue.
|
25
|
+
# @option options [String] ll Latitude and longitude of the venue, as accurate as is known.
|
26
|
+
# @option options [String] primaryCategoryId The id of the category to which you want to assign this venue.
|
27
|
+
# @return [Hashie::Mash] Details about the venue that was just added.
|
28
|
+
# @requires_acting_user Yes
|
29
|
+
# @see http://developer.foursquare.com/docs/venues/add.html
|
30
|
+
def add_venue(name, options = {})
|
31
|
+
post('venues/add', { :name => name }.merge(options)).venue
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns a hierarchical list of categories applied to venues. Note
|
35
|
+
# that top-level categories do not have ids because they cannot be
|
36
|
+
# assigned to a venue.
|
37
|
+
#
|
38
|
+
# Category images that come down through the API are available in three
|
39
|
+
# sizes:
|
40
|
+
# * 32 x 32 (default)
|
41
|
+
# * 64 x 64
|
42
|
+
# * 256 x 256
|
43
|
+
# @return [Hashie::Mash] A heirarchical list of categories applied to venues.
|
44
|
+
# @requires_acting_user No
|
45
|
+
# @see http://developer.foursquare.com/docs/venues/categories.html
|
46
|
+
def categories
|
47
|
+
get('venues/categories').categories
|
48
|
+
end
|
49
|
+
|
50
|
+
# Allows a user to indicated a venue is incorrect in some way.
|
51
|
+
#
|
52
|
+
# @param id [String] The venue id for which an edit is being proposed.
|
53
|
+
# @param problem [String] One of mislocated, closed, duplicate.
|
54
|
+
# @require_acting_user Yes
|
55
|
+
# @see http://developer.foursquare.com/docs/venues/flag.html
|
56
|
+
def flag_venue(id, problem)
|
57
|
+
post("venues/#{id}/flag", { :problem => problem })
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
61
|
+
# Provides a count of how many people are at a given venue, plus the
|
62
|
+
# first page of the users there, friends-first, and if the current user
|
63
|
+
# is authenticated.
|
64
|
+
#
|
65
|
+
# @note This is an experimental API.
|
66
|
+
# @param id [String] Id of a venue to retrieve.
|
67
|
+
# @param options [Hash] A customizable set of options.
|
68
|
+
# @option options [Integer] limit Number of results to return, up to 500.
|
69
|
+
# @option options [Integer] offset Used to page through results.
|
70
|
+
# @option options [Integer] afterTimestamp Retrieve the first results to follow these seconds since epoch.
|
71
|
+
# @return [Hashie::Mash] A count of items where items are checkins.
|
72
|
+
# @requires_acting_user No
|
73
|
+
# @see http://developer.foursquare.com/docs/venues/herenow.html
|
74
|
+
def herenow(id, options = {})
|
75
|
+
get("venues/#{id}/herenow", options).hereNow
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns photos for a venue.
|
79
|
+
#
|
80
|
+
# @param id [String] The venue you want photos for.
|
81
|
+
# @param group [String] One of checkin, venue or multi (for both).
|
82
|
+
# @param options [Hash] A customizable set of options.
|
83
|
+
# @option options [Integer] limit Number of results to return, up to 500.
|
84
|
+
# @option options [Integer] offset Used to page through results.
|
85
|
+
# @return [Hashie::Mash] A count of items of photo.
|
86
|
+
# @requires_acting_user No
|
87
|
+
# @see http://developer.foursquare.com/docs/venues/photos.html
|
88
|
+
def photos(id, group = 'checkin', options = {})
|
89
|
+
get("venues/#{id}/photos", {:group => group }.merge(options)).photos
|
90
|
+
end
|
91
|
+
|
92
|
+
# Allows you to propose a change to a venue.
|
93
|
+
#
|
94
|
+
# @param id [String] The venue id for which an edit is being proposed.
|
95
|
+
# @param name [String] The name of the venue.
|
96
|
+
# @param address [String] The address of the venue.
|
97
|
+
# @param city [String] The city name where the venue is.
|
98
|
+
# @param state [String] The nearest state or province to the venue.
|
99
|
+
# @param zip [String] The zip or postal code for the venue.
|
100
|
+
# @param ll [String] Latitude and longitude of the venue's location, as accurate as is known.
|
101
|
+
# @param options [Hash] A customizable set of options.
|
102
|
+
# @option options [String] crossStreet The nearest intersecting street or streets.
|
103
|
+
# @option options [String] phone The phone number of the venue.
|
104
|
+
# @option options [String] primaryCategoryId The id of the category to which you want to assign this venue.
|
105
|
+
# @return nil
|
106
|
+
# @requires_acting_user Yes
|
107
|
+
# @see http://developer.foursquare.com/docs/venues/proposeedit.html
|
108
|
+
def proposeedit(id, name, address, city, state, zip, ll, options = {})
|
109
|
+
post("venues/#{id}/proposeedit", {
|
110
|
+
:name => name,
|
111
|
+
:address => address,
|
112
|
+
:city => city,
|
113
|
+
:state => state,
|
114
|
+
:zip => zip,
|
115
|
+
:ll => ll
|
116
|
+
}.merge(options))
|
117
|
+
nil
|
118
|
+
end
|
119
|
+
|
120
|
+
# Gives details about a venue, including location, mayorship, tags, tips,
|
121
|
+
# specials and category.
|
122
|
+
#
|
123
|
+
# Authenticated users will also receive information about who is here now.
|
124
|
+
#
|
125
|
+
# If the venue id given is one that has been merged into another "master"
|
126
|
+
# venue, the response will show data about the "master" instead of giving
|
127
|
+
# you an error.
|
128
|
+
#
|
129
|
+
# @param id [String] Id of a venue to retrieve.
|
130
|
+
# @return [Hashie::Mash] Details about a venue, including location, mayorship, tags, tips, specials, and category.
|
131
|
+
# @requires_acting_user No
|
132
|
+
# @see http://developer.foursquare.com/docs/venues/venues.html
|
133
|
+
def venue(id)
|
134
|
+
get("venues/#{id}").venue
|
135
|
+
end
|
136
|
+
|
137
|
+
# Allows a user to mark a venue to-do, with optional text.
|
138
|
+
#
|
139
|
+
# @param id The venue you want to mark to-do.
|
140
|
+
# @param options [Hash] A customizable set of options.
|
141
|
+
# @option options [String] text The text of the tip.
|
142
|
+
# @return [Hashie::Mash] The newly-added to-do, which contains a tip created implicitly.
|
143
|
+
# @requires_acting_user Yes
|
144
|
+
# @see http://developer.foursquare.com/docs/venues/marktodo.html
|
145
|
+
def venue_marktodo(id, options = {})
|
146
|
+
post("venues/#{id}/marktodo").todo
|
147
|
+
end
|
148
|
+
|
149
|
+
# Returns a list of venues near the current location, optionally matching
|
150
|
+
# the search term.
|
151
|
+
#
|
152
|
+
# If lat and long is provided, each venue includes a distance. If
|
153
|
+
# authenticated, the method will return venue metadata related to you and
|
154
|
+
# your friends. If you do not authenticate, you will not get this data.
|
155
|
+
#
|
156
|
+
# @param ll [String] Latitude and longitude of the user's location, so response can include distance.
|
157
|
+
# @param options [Hash] A customizable set of options.
|
158
|
+
# @option options [Decimal] llAcc Accuracy of latitude and longitude, in meters.
|
159
|
+
# @option options [Decimal] alt Altitude of the user's location, in meters.
|
160
|
+
# @option options [Decimal] altAcc Accuracy of the user's altitude, in meters.
|
161
|
+
# @option options [String] query A search term to be applied against titles.
|
162
|
+
# @option options [Integer] limit Number of results to return, up to 50.
|
163
|
+
# @option options [String] intent Indicates your intent in performing the search.
|
164
|
+
# @return [Hashie::Mash] An array of objects representing groups of venues.
|
165
|
+
# @requires_acting_user No
|
166
|
+
# @see http://developer.foursquare.com/docs/venues/search.html
|
167
|
+
def venue_search(ll, options = {})
|
168
|
+
get('venues/search', { :ll => ll }.merge(options)).groups
|
169
|
+
end
|
170
|
+
|
171
|
+
# Returns tips for a venue.
|
172
|
+
#
|
173
|
+
# @param id [String] The venue you want tips for.
|
174
|
+
# @param options [Hash] A customizable set of options.
|
175
|
+
# @option options [String] sort One of recent or popular.
|
176
|
+
# @option options [Integer] limit Number of results to return, up to 500.
|
177
|
+
# @option options [Integer] offset Used to page through results.
|
178
|
+
# @return [Hashie::Mash] A count of items of tips.
|
179
|
+
# @requires_acting_user No
|
180
|
+
# @see http://developer.foursquare.com/docs/venues/tips.html
|
181
|
+
def venue_tips(id, options = {})
|
182
|
+
get("venues/#{id}/tips", options).tips
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Adapted from the Ruby Twitter gem.
|
2
|
+
# @see https://github.com/jnunemaker/twitter
|
3
|
+
module Skittles
|
4
|
+
# Defines constants and methods related to configuration.
|
5
|
+
module Configuration
|
6
|
+
# An array of valid keys in the options hash when configuring a {Flixated::API}.
|
7
|
+
VALID_OPTIONS_KEYS = [
|
8
|
+
:access_token,
|
9
|
+
:authorization_endpoint,
|
10
|
+
:client_id,
|
11
|
+
:client_secret,
|
12
|
+
:endpoint,
|
13
|
+
:proxy,
|
14
|
+
:user_agent
|
15
|
+
].freeze
|
16
|
+
|
17
|
+
# By default, don't set a user access token.
|
18
|
+
DEFAULT_ACCESS_TOKEN = nil.freeze
|
19
|
+
|
20
|
+
# The endpoint that will be used to authorize a user if none is set.
|
21
|
+
DEFAULT_AUTHORIZATION_ENDPOINT = 'https://foursquare.com/oauth2/authenticate'.freeze
|
22
|
+
|
23
|
+
# By default, don't set a client id.
|
24
|
+
DEFAULT_CLIENT_ID = nil.freeze
|
25
|
+
|
26
|
+
# By default, don't set a cliet secret.
|
27
|
+
DEFAULT_CLIENT_SECRET = nil.freeze
|
28
|
+
|
29
|
+
# The endpoint that will be used to connect if none is set.
|
30
|
+
DEFAULT_ENDPOINT = 'https://api.foursquare.com/v2'.freeze
|
31
|
+
|
32
|
+
# By default, don't set a proxy server.
|
33
|
+
DEFAULT_PROXY = nil.freeze
|
34
|
+
|
35
|
+
# The user agent that will be setn to the API endpoint if none is set.
|
36
|
+
DEFAULT_USER_AGENT = "skittles gem v#{Skittles::VERSION}".freeze
|
37
|
+
|
38
|
+
# @private
|
39
|
+
attr_accessor(*VALID_OPTIONS_KEYS)
|
40
|
+
|
41
|
+
# When this module is extended, set all configuration options to their default values.
|
42
|
+
def self.extended(base)
|
43
|
+
base.reset
|
44
|
+
end
|
45
|
+
|
46
|
+
# Convenience method to allow configuration options to be set in a block.
|
47
|
+
def configure
|
48
|
+
yield self
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create a hash of options and their values.
|
52
|
+
def options
|
53
|
+
VALID_OPTIONS_KEYS.inject({}) do |option,key|
|
54
|
+
option.merge!(key => send(key))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Reset all configuration options to default.
|
59
|
+
def reset
|
60
|
+
self.access_token = DEFAULT_ACCESS_TOKEN
|
61
|
+
self.authorization_endpoint = DEFAULT_AUTHORIZATION_ENDPOINT
|
62
|
+
self.client_id = DEFAULT_CLIENT_ID
|
63
|
+
self.client_secret = DEFAULT_CLIENT_SECRET
|
64
|
+
self.endpoint = DEFAULT_ENDPOINT
|
65
|
+
self.proxy = DEFAULT_PROXY
|
66
|
+
self.user_agent = DEFAULT_USER_AGENT
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'oauth2'
|
2
|
+
|
3
|
+
module Skittles
|
4
|
+
# @private
|
5
|
+
module Connection
|
6
|
+
private
|
7
|
+
def connection
|
8
|
+
options = {
|
9
|
+
:site => endpoint
|
10
|
+
}
|
11
|
+
puts
|
12
|
+
client = OAuth2::Client.new(client_id, client_secret, options)
|
13
|
+
oauth_token = OAuth2::AccessToken.new(client, access_token)
|
14
|
+
|
15
|
+
oauth_token.token_param = 'oauth_token'
|
16
|
+
oauth_token
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'yajl'
|
3
|
+
require 'hashie'
|
4
|
+
|
5
|
+
module Skittles
|
6
|
+
module Request
|
7
|
+
# Perform an HTTP GET request
|
8
|
+
def get(path, options = {}, raw = false)
|
9
|
+
request(:get, path, options, raw)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Performs an HTTP POST request
|
13
|
+
def post(path, options = {}, raw = false)
|
14
|
+
request(:post, path, options, raw)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Performs an HTTP PUT request
|
18
|
+
def put(path, options = {}, raw = false)
|
19
|
+
request(:put, path, options, raw)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Performs an HTTP DELETE request
|
23
|
+
def delete(path, options = {}, raw = false)
|
24
|
+
request(:delete, path, options, raw)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
#Perform an HTTP request
|
29
|
+
def request(method, path, options, raw)
|
30
|
+
headers = {
|
31
|
+
'User-Agent' => user_agent
|
32
|
+
}
|
33
|
+
|
34
|
+
options.merge!({
|
35
|
+
:client_id => client_id,
|
36
|
+
:client_secret => client_secret
|
37
|
+
})
|
38
|
+
response = connection.request(method, paramify(path, options), headers)
|
39
|
+
|
40
|
+
unless raw
|
41
|
+
result = Yajl::Parser.new.parse(response)
|
42
|
+
end
|
43
|
+
|
44
|
+
raw ? response : Hashie::Mash.new(result).response
|
45
|
+
end
|
46
|
+
|
47
|
+
# Encode path and turn params into HTTP query.
|
48
|
+
def paramify(path, params)
|
49
|
+
URI.encode("#{path}?#{params.map { |k,v| "#{k}=#{v}" }.join('&')}")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'skittles'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,253 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: skittles
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anthony Smith
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-22 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: oauth2
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ~>
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.1.1
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yajl-ruby
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 0.8.1
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: hashie
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.0.0
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rspec
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ~>
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 2.5.0
|
57
|
+
type: :development
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: bundler
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ~>
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 1.0.10
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: jeweler
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ~>
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.5.2
|
79
|
+
type: :development
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rcov
|
84
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: "0"
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: *id007
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: yard
|
95
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 0.6.4
|
101
|
+
type: :development
|
102
|
+
prerelease: false
|
103
|
+
version_requirements: *id008
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: oauth2
|
106
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.1.1
|
112
|
+
type: :runtime
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: *id009
|
115
|
+
- !ruby/object:Gem::Dependency
|
116
|
+
name: yajl-ruby
|
117
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
119
|
+
requirements:
|
120
|
+
- - ~>
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 0.8.1
|
123
|
+
type: :runtime
|
124
|
+
prerelease: false
|
125
|
+
version_requirements: *id010
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: hashie
|
128
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.0.0
|
134
|
+
type: :runtime
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: *id011
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: rspec
|
139
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ~>
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: 2.5.0
|
145
|
+
type: :development
|
146
|
+
prerelease: false
|
147
|
+
version_requirements: *id012
|
148
|
+
- !ruby/object:Gem::Dependency
|
149
|
+
name: bundler
|
150
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
151
|
+
none: false
|
152
|
+
requirements:
|
153
|
+
- - ~>
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: 1.0.10
|
156
|
+
type: :development
|
157
|
+
prerelease: false
|
158
|
+
version_requirements: *id013
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: jeweler
|
161
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 1.5.2
|
167
|
+
type: :development
|
168
|
+
prerelease: false
|
169
|
+
version_requirements: *id014
|
170
|
+
- !ruby/object:Gem::Dependency
|
171
|
+
name: rcov
|
172
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
173
|
+
none: false
|
174
|
+
requirements:
|
175
|
+
- - ">="
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: "0"
|
178
|
+
type: :development
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: *id015
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: yard
|
183
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ~>
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: 0.6.4
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: *id016
|
192
|
+
description: Foursquare v2 REST API client library for Ruby
|
193
|
+
email: anthony@sticksnleaves.com
|
194
|
+
executables: []
|
195
|
+
|
196
|
+
extensions: []
|
197
|
+
|
198
|
+
extra_rdoc_files:
|
199
|
+
- LICENSE.txt
|
200
|
+
- README.rdoc
|
201
|
+
files:
|
202
|
+
- lib/skittles.rb
|
203
|
+
- lib/skittles/api.rb
|
204
|
+
- lib/skittles/client.rb
|
205
|
+
- lib/skittles/client/checkin.rb
|
206
|
+
- lib/skittles/client/photo.rb
|
207
|
+
- lib/skittles/client/setting.rb
|
208
|
+
- lib/skittles/client/special.rb
|
209
|
+
- lib/skittles/client/tip.rb
|
210
|
+
- lib/skittles/client/user.rb
|
211
|
+
- lib/skittles/client/venue.rb
|
212
|
+
- lib/skittles/configuration.rb
|
213
|
+
- lib/skittles/connection.rb
|
214
|
+
- lib/skittles/request.rb
|
215
|
+
- lib/skittles/version.rb
|
216
|
+
- LICENSE.txt
|
217
|
+
- README.rdoc
|
218
|
+
- spec/skittles_spec.rb
|
219
|
+
- spec/spec_helper.rb
|
220
|
+
has_rdoc: true
|
221
|
+
homepage: http://github.com/anthonator/skittles
|
222
|
+
licenses:
|
223
|
+
- MIT
|
224
|
+
post_install_message:
|
225
|
+
rdoc_options: []
|
226
|
+
|
227
|
+
require_paths:
|
228
|
+
- lib
|
229
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
230
|
+
none: false
|
231
|
+
requirements:
|
232
|
+
- - ">="
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
hash: 3194088974280100972
|
235
|
+
segments:
|
236
|
+
- 0
|
237
|
+
version: "0"
|
238
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
|
+
none: false
|
240
|
+
requirements:
|
241
|
+
- - ">="
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: "0"
|
244
|
+
requirements: []
|
245
|
+
|
246
|
+
rubyforge_project:
|
247
|
+
rubygems_version: 1.5.2
|
248
|
+
signing_key:
|
249
|
+
specification_version: 3
|
250
|
+
summary: Foursquare v2 REST API client library for Ruby
|
251
|
+
test_files:
|
252
|
+
- spec/skittles_spec.rb
|
253
|
+
- spec/spec_helper.rb
|