cmdrkeene-foursquare 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ Until further notice: Copyright 2009 Brandon Keene - All Rights Reserved
data/README ADDED
@@ -0,0 +1,11 @@
1
+ = A Ruby API for Foursquare (playfoursquare.com)
2
+
3
+
4
+ == Supported Actions
5
+
6
+ == Check In
7
+
8
+ To check into a venue by id:
9
+
10
+ @foursquare = Foursquare.new(username, password)
11
+ @foursquare.check_in(12345) # => {"score" => {...}, ...}
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "foursquare"
5
+ gemspec.summary = "Ruby API for Foursquare (playfoursquare.com)"
6
+ gemspec.description = "Ruby API for Foursquare (playfoursquare.com)"
7
+ gemspec.email = "bkeene@gmail.com"
8
+ gemspec.homepage = "http://github.com/cmdrkeene/foursquare"
9
+ gemspec.authors = ["Brandon Keene"]
10
+ gemspec.add_dependency('httparty', '>= 0.4.4')
11
+ end
12
+ rescue LoadError
13
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
14
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.2
@@ -0,0 +1,54 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE
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{foursquare}
8
+ s.version = "0.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Brandon Keene"]
12
+ s.date = %q{2009-08-12}
13
+ s.description = %q{Ruby API for Foursquare (playfoursquare.com)}
14
+ s.email = %q{bkeene@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README"
18
+ ]
19
+ s.files = [
20
+ "LICENSE",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "foursquare.gemspec",
25
+ "init.rb",
26
+ "lib/foursquare.rb",
27
+ "spec/fixtures/checkin_failure.json",
28
+ "spec/fixtures/checkin_success.json",
29
+ "spec/foursquare_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = %q{http://github.com/cmdrkeene/foursquare}
33
+ s.rdoc_options = ["--charset=UTF-8"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = %q{1.3.5}
36
+ s.summary = %q{Ruby API for Foursquare (playfoursquare.com)}
37
+ s.test_files = [
38
+ "spec/foursquare_spec.rb",
39
+ "spec/spec_helper.rb"
40
+ ]
41
+
42
+ if s.respond_to? :specification_version then
43
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
47
+ s.add_runtime_dependency(%q<httparty>, [">= 0.4.4"])
48
+ else
49
+ s.add_dependency(%q<httparty>, [">= 0.4.4"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<httparty>, [">= 0.4.4"])
53
+ end
54
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'lib/foursquare'
data/lib/foursquare.rb ADDED
@@ -0,0 +1,20 @@
1
+ require 'httparty'
2
+
3
+ class Foursquare
4
+ class VenueNotFoundError < StandardError;end
5
+
6
+ include HTTParty
7
+ base_uri "http://api.playfoursquare.com/v1"
8
+ format :json
9
+
10
+ def initialize(username, password)
11
+ @auth = {:username => username, :password => password}
12
+ end
13
+
14
+ def checkin(venue_id)
15
+ raise ArgumentError, "you must pass a venue_id" unless venue_id
16
+ response = self.class.post("/checkin.json", {:query => {:vid => venue_id}, :basic_auth => @auth})
17
+ raise VenueNotFoundError if response.keys.include?("addvenueprompt")
18
+ response["checkin"]
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ "addvenueprompt":null
@@ -0,0 +1 @@
1
+ {"checkin":{"message":"OK! We've got you @ Santana's Bay Park.","id":701707,"created":"Tue, 11 Aug 09 16:02:13 +0000","venue":{"id":84689,"name":"Santana's Bay Park","address":"1975 Morena Blvd.","crossstreet":null,"city":"San Diego","state":"CA","zip":92110,"cityid":38,"geolat":32.782,"geolong":-117.207},"badges":{"badge":{"id":54494,"name":"Newbie","icon":"http://playfoursquare.com/images/badges/newbie_on.png","text":"Congrats on your first check-in!"}},"scoring":{"score":{"points":5,"icon":"http://playfoursquare.com/images/scoring/1.png","message":"First time @ Santana's Bay Park!"},"score":{"points":1,"icon":"http://playfoursquare.com/images/scoring/2.png","message":"First stop today"},"total":{"points":6,"message":"6 pts "},"rank":{"friends":{"position":1,"message":"#1 amongst friends"},"city":{"position":42,"city":"San Diego","message":"#42 in San Diego (this week)"}}},"mayor":{"type":"nochange","message":"Casey W. is The Mayor of Santana's Bay Park."}}}
@@ -0,0 +1,88 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/../init'
3
+
4
+ describe Foursquare do
5
+ describe ".checkin" do
6
+ before do
7
+ @valid_venue_id = 84689
8
+ @invalid_venue_id = 111
9
+ @username = "user@example.com"
10
+ @password = "secret"
11
+
12
+ # Success
13
+ FakeWeb.register_uri(:post,
14
+ "http://api.playfoursquare.com/v1/checkin.json?vid=#{@valid_venue_id}",
15
+ :body => "Unauthorized",
16
+ :status => ["401", "Unauthorized"])
17
+ FakeWeb.register_uri(:post,
18
+ "http://user%40example.com:secret@api.playfoursquare.com/v1/checkin.json?vid=#{@valid_venue_id}",
19
+ :body => fakeweb_read('checkin_success.json'))
20
+
21
+ # Failure
22
+ FakeWeb.register_uri(:post,
23
+ "http://api.playfoursquare.com/v1/checkin.json?vid=#{@invalid_venue_id}",
24
+ :body => "Unauthorized",
25
+ :status => ["401", "Unauthorized"])
26
+ FakeWeb.register_uri(:post,
27
+ "http://user%40example.com:secret@api.playfoursquare.com/v1/checkin.json?vid=#{@invalid_venue_id}",
28
+ :body => fakeweb_read('checkin_failure.json'))
29
+ end
30
+
31
+ it "should require a venue_id" do
32
+ lambda {
33
+ Foursquare.new(@username, @password).checkin
34
+ }.should raise_error(ArgumentError)
35
+ end
36
+
37
+ it "should raise an error if user is invalid" do
38
+ lambda {
39
+ Foursquare.new("bork@pork.com", "arglebargle").checkin(@valid_venue_id)
40
+ }.should raise_error
41
+ end
42
+
43
+ describe "to a valid venue, with a valid user" do
44
+ it "should check in and return check in data" do
45
+ @foursquare = Foursquare.new(@username, @password)
46
+ checkin = @foursquare.checkin(@valid_venue_id)
47
+ checkin.should == {
48
+ "mayor" => {"type"=>"nochange", "message"=>"Casey W. is The Mayor of Santana's Bay Park."},
49
+ "scoring" => {
50
+ "score" => {"icon"=>"http://playfoursquare.com/images/scoring/2.png", "points"=>1, "message"=>"First stop today"},
51
+ "total" => {"points"=>6, "message"=>"6 pts "},
52
+ "rank" => {
53
+ "city" => {"city"=>"San Diego", "position"=>42, "message"=>"#42 in San Diego (this week)"},
54
+ "friends" => {"position"=>1, "message"=>"#1 amongst friends"}
55
+ },
56
+ },
57
+ "id" => 701707,
58
+ "badges" => {
59
+ "badge" => {"name"=>"Newbie", "text"=>"Congrats on your first check-in!", "icon"=>"http://playfoursquare.com/images/badges/newbie_on.png", "id"=>54494}
60
+ },
61
+ "venue" => {"city"=>"San Diego", "address"=>"1975 Morena Blvd.", "name"=>"Santana's Bay Park", "zip"=>92110, "geolong"=>-117.207, "geolat"=>32.782, "crossstreet"=>nil, "id"=>84689, "cityid"=>38, "state"=>"CA"},
62
+ "message" => "OK! We've got you @ Santana's Bay Park.", "created"=>"Tue, 11 Aug 09 16:02:13 +0000"
63
+ }
64
+ end
65
+ end
66
+
67
+ describe "with an invalid venue" do
68
+ it "should raise an error" do
69
+ lambda {
70
+ @foursquare = Foursquare.new(@username, @password)
71
+ @foursquare.checkin(@invalid_venue_id).should == "foo"
72
+ }.should raise_error(Foursquare::VenueNotFoundError)
73
+ end
74
+ end
75
+ end
76
+
77
+ describe ".city" do
78
+ end
79
+
80
+ describe ".tip" do
81
+ end
82
+
83
+ describe ".user" do
84
+ end
85
+
86
+ describe ".venue" do
87
+ end
88
+ end
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'spork'
3
+ require 'fakeweb'
4
+
5
+ Spork.prefork do
6
+ require 'spec/autorun'
7
+
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ FakeWeb.allow_net_connect = false
11
+
12
+ Spec::Runner.configure do |config|
13
+ # nothing
14
+ end
15
+ end
16
+
17
+ Spork.each_run do
18
+ # nothing
19
+ end
20
+
21
+ def fakeweb_read(filename)
22
+ File.read(File.join(File.dirname(__FILE__), "fixtures", filename))
23
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cmdrkeene-foursquare
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Brandon Keene
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.4
24
+ version:
25
+ description: Ruby API for Foursquare (playfoursquare.com)
26
+ email: bkeene@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README
34
+ files:
35
+ - LICENSE
36
+ - README
37
+ - Rakefile
38
+ - VERSION
39
+ - foursquare.gemspec
40
+ - init.rb
41
+ - lib/foursquare.rb
42
+ - spec/fixtures/checkin_failure.json
43
+ - spec/fixtures/checkin_success.json
44
+ - spec/foursquare_spec.rb
45
+ - spec/spec_helper.rb
46
+ has_rdoc: false
47
+ homepage: http://github.com/cmdrkeene/foursquare
48
+ licenses:
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --charset=UTF-8
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Ruby API for Foursquare (playfoursquare.com)
73
+ test_files:
74
+ - spec/foursquare_spec.rb
75
+ - spec/spec_helper.rb