Class: Foursquare::Node
- Inherits:
-
Object
- Object
- Foursquare::Node
- Defined in:
- lib/foursquare_node.rb
Instance Method Summary collapse
-
#initialize(access_token) ⇒ Node
constructor
A new instance of Node.
- #perform_graph_request(endpoint, params = {}, method = "get") ⇒ Object
Constructor Details
#initialize(access_token) ⇒ Node
Returns a new instance of Node.
4 5 6 7 |
# File 'lib/foursquare_node.rb', line 4 def initialize(access_token) @access_token = access_token @base_url = "https://api.foursquare.com:443/v2/" end |
Instance Method Details
#perform_graph_request(endpoint, params = {}, method = "get") ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/foursquare_node.rb', line 9 def perform_graph_request(endpoint, params={}, method="get") require 'net/http' @query_string = "?" @query_string += "oauth_token=#{CGI.escape(@access_token)}" unless @access_token.blank? if method=="get" params.each{|key, val| @query_string += "&#{key}=#{val}"} url = URI.parse("#{@base_url}#{endpoint}#{@query_string}") request = Net::HTTP::Get.new("#{url.path}?#{url.query}",{"Content-Type"=>"text/json"}) else url = URI.parse("#{@base_url}#{endpoint}#{@query_string}") request = Net::HTTP::Post.new("#{url.path}?#{url.query}",{"Content-Type"=>"text/json"}) request.set_form_data(params) end http = Net::HTTP.new(url.host, url.port) http.use_ssl = true response = JSON.parse(http.start {|http| http.request(request) }.body) response end |