Sha256: be97943b36599f4d3cdab111170b0de2d7f634a59b2f7697494430ae99738859
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
require 'twitter/default' require 'twitter/api/timelines' require 'net/http' require 'uri' require 'json' module Twitter # @note Inspired from gems\twitter-4.5.0\spec\twitter\tweet_spec.rb class Client ConnectionError = Class.new(StandardError) include Twitter::API::Timelines # Perform an HTTP GET request # qry = [['slug', 'élgalu'], ['age', '31']] def get(path, qry=[]) uri = build_uri(path, qry) begin result = Net::HTTP.get(uri) rescue => ex pute uri, "Some network connection error: #{ex.inspect}" end pute uri, "The result contains errors: #{result}" if result =~ /error/ JSON.parse(result) end private def build_uri(path, qry=[]) query = URI.encode_www_form(qry) path.chomp!('/') path.sub!(/^\//, '') base = Twitter::Default::ENDPOINT ver = Twitter::Default::API_VERSION URI.parse("#{base}/#{ver}/#{path}?#{query}") end def pute(uri, msg) raise ConnectionError.new("#{msg}\nRequest: #{uri.to_s}\n") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
twitter_anonymous_client-0.0.1 | lib/twitter/client.rb |