diff --git a/README.md b/README.md index 44dc154..c3890d5 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It's a Foursquare API wrapper. It uses objects instead of hashes, and tries to b Install it as a gem (in your `Gemfile`) and its dependencies: gem "json" - gem "typhoeus" + gem "httparty" gem "quimby" ## Usage @@ -114,4 +114,4 @@ if you want to use your own logger, and you're kind of a jerk like me, you can d * Creating checkins works, but it should really return notifications. Also, if the checkin can't be created, it should return errors. -* I don't know, so much other stuff. \ No newline at end of file +* I don't know, so much other stuff. diff --git a/lib/foursquare.rb b/lib/foursquare.rb index 262203c..df53450 100644 --- a/lib/foursquare.rb +++ b/lib/foursquare.rb @@ -1,7 +1,7 @@ $LOAD_PATH << File.dirname(__FILE__) require "rubygems" -require "typhoeus" +require "httparty" require "json" require "cgi" require "foursquare/base" @@ -16,6 +16,7 @@ require "foursquare/photo" require "foursquare/location" require "foursquare/category" +require "foursquare/checkin_comment" module Foursquare class Error < StandardError ; end @@ -42,7 +43,7 @@ def self.log(msg) "not_authorized" => "Although authentication succeeded, the acting user is not allowed to see this information due to privacy restrictions.", "rate_limit_exceeded" => "Rate limit for this hour exceeded.", "deprecated" => "Something about this request is using deprecated functionality, or the response format may be about to change.", - "server_error" => "Server is currently experiencing issues. Check status.foursquare.com for udpates.", + "server_error" => "Server is currently experiencing issues. Check status.foursquare.com for updates.", "other" => "Some other type of error occurred." } end diff --git a/lib/foursquare/base.rb b/lib/foursquare/base.rb index ee7049c..1ff3a25 100644 --- a/lib/foursquare/base.rb +++ b/lib/foursquare/base.rb @@ -34,7 +34,7 @@ def get(path, params={}) Foursquare.log("GET #{API + path}") Foursquare.log("PARAMS: #{params.inspect}") merge_auth_params(params) - response = JSON.parse(Typhoeus::Request.get(API + path, :params => params).body) + response = JSON.parse(HTTParty.get(API + path, :query => params).body) Foursquare.log(response.inspect) error(response) || response["response"] end @@ -44,37 +44,37 @@ def post(path, params={}) Foursquare.log("POST #{API + path}") Foursquare.log("PARAMS: #{params.inspect}") merge_auth_params(params) - response = JSON.parse(Typhoeus::Request.post(API + path, :params => params).body) + response = JSON.parse(HTTParty.post(API + path, :query => params).body) Foursquare.log(response.inspect) error(response) || response["response"] end - + def authorize_url(redirect_uri) # http://developer.foursquare.com/docs/oauth.html - + # check params raise "you need to define a client id before" if @client_id.blank? raise "no callback url provided" if redirect_uri.blank? - + # params params = {} params["client_id"] = @client_id params["response_type"] = "code" params["redirect_uri"] = redirect_uri - + # url oauth2_url('authenticate', params) end - + def access_token(code, redirect_uri) # http://developer.foursquare.com/docs/oauth.html - + # check params raise "you need to define a client id before" if @client_id.blank? raise "you need to define a client secret before" if @client_secret.blank? raise "no code provided" if code.blank? raise "no redirect_uri provided" if redirect_uri.blank? - + # params params = {} params["client_id"] = @client_id @@ -82,18 +82,18 @@ def access_token(code, redirect_uri) params["grant_type"] = "authorization_code" params["redirect_uri"] = redirect_uri params["code"] = code - + # url url = oauth2_url('access_token', params) - + # response # http://developer.foursquare.com/docs/oauth.html - response = JSON.parse(Typhoeus::Request.get(url).body) + response = JSON.parse(HTTParty.get(url).body) response["access_token"] end private - + def oauth2_url(method_name, params) "https://foursquare.com/oauth2/#{method_name}?#{params.to_query}" end diff --git a/lib/foursquare/checkin.rb b/lib/foursquare/checkin.rb index f540ea9..d79b47b 100644 --- a/lib/foursquare/checkin.rb +++ b/lib/foursquare/checkin.rb @@ -35,6 +35,20 @@ def mayor? @json["isMayor"] end + def comments + fetch if @json["comments"].nil? || (@json["comments"]["count"] > 0 && @json["comments"]["items"].length == 0) + @json["comments"]["items"].map { |comment| Foursquare::CheckinComment.new(@foursquare, comment) } + end + + def overlaps + fetch unless @json["overlaps"] + if @json["overlaps"] && @json["overlaps"]["items"] + @json["overlaps"]["items"].map { |checkin| Foursquare::Checkin.new(@foursquare, checkin) } + else + [] + end + end + def timezone @json["timeZone"] end diff --git a/lib/foursquare/checkin_comment.rb b/lib/foursquare/checkin_comment.rb new file mode 100644 index 0000000..c4f37eb --- /dev/null +++ b/lib/foursquare/checkin_comment.rb @@ -0,0 +1,29 @@ +module Foursquare + class CheckinComment + attr_reader :json + + def initialize(foursquare, json) + @foursquare, @json = foursquare, json + end + + def id + @json["id"] + end + + def created_at + Time.at(@json["createdAt"].to_i) + end + + def text + @json["text"] + end + + def user(full=false) + if full + @foursquare.users.find(@json["user"]["id"]) + else + Foursquare::User.new(@foursquare, @json["user"]) + end + end + end +end diff --git a/quimby.gemspec b/quimby.gemspec index 201f231..75b97aa 100644 --- a/quimby.gemspec +++ b/quimby.gemspec @@ -37,14 +37,14 @@ Gem::Specification.new do |s| s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then - s.add_runtime_dependency(%q, [">= 0"]) + s.add_runtime_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 0"]) else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end else - s.add_dependency(%q, [">= 0"]) + s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 0"]) end end