Class: Datarank::Client
- Inherits:
-
Object
- Object
- Datarank::Client
- Includes:
- Comments, Datasources, Fizzle, Interaction, Likes, Live, Locations, Reach, Retailers, Search, Sentiment, SocialStats, Themes, TopicAdministration, Topics, Volume, Wordcloud, HTTParty
- Defined in:
- lib/datarank/live.rb,
lib/datarank/likes.rb,
lib/datarank/reach.rb,
lib/datarank/client.rb,
lib/datarank/fizzle.rb,
lib/datarank/search.rb,
lib/datarank/themes.rb,
lib/datarank/topics.rb,
lib/datarank/volume.rb,
lib/datarank/comments.rb,
lib/datarank/locations.rb,
lib/datarank/retailers.rb,
lib/datarank/sentiment.rb,
lib/datarank/wordcloud.rb,
lib/datarank/datasources.rb,
lib/datarank/interaction.rb,
lib/datarank/social_stats.rb,
lib/datarank/topic_administration.rb
Defined Under Namespace
Modules: Comments, Datasources, Fizzle, Interaction, Likes, Live, Locations, Reach, Retailers, Search, Sentiment, SocialStats, Themes, TopicAdministration, Topics, Volume, Wordcloud Classes: Error
Constant Summary collapse
- BASE_URI =
'https://api.datarank.com'
Instance Method Summary collapse
- #delete(path, options = {}) ⇒ Object
-
#get(path, options = {}) ⇒ Object
Wrappers for the main HTTP verbs.
- #http_verb(verb, path, options = {}) ⇒ Object
-
#initialize(api_key = nil, api_version = nil, options = {}) ⇒ Client
constructor
A new instance of Client.
- #post(path, options = {}) ⇒ Object
- #put(path, options = {}) ⇒ Object
Methods included from TopicAdministration
#create_topic, #delete_topic, #edit_topic
Methods included from SocialStats
Methods included from Search
Methods included from Wordcloud
Methods included from Volume
#volume_daily, #volume_hourly, #volume_hourly_average, #volume_minutely, #volume_monthly, #volume_quarterly, #volume_secondly, #volume_weekday, #volume_weekday_heatmap_hourly, #volume_weekly, #volume_yearly
Methods included from Themes
#themes, #themes_correlation, #themes_trend
Methods included from Sentiment
#sentiment_daily, #sentiment_hourly, #sentiment_minutely, #sentiment_monthly, #sentiment_quarterly, #sentiment_secondly, #sentiment_weekly, #sentiment_yearly
Methods included from Retailers
Methods included from Reach
#reach_daily, #reach_hourly, #reach_minutely, #reach_monthly, #reach_quarterly, #reach_secondly, #reach_weekly, #reach_yearly
Methods included from Locations
#location_heatmap, #location_pins, #location_provinces
Methods included from Live
#tweets, #twitter_volume_daily
Methods included from Likes
#likes_daily, #likes_hourly, #likes_minutely, #likes_monthly, #likes_quarterly, #likes_secondly, #likes_weekly, #likes_yearly
Methods included from Interaction
#interaction_daily, #interaction_hourly, #interaction_minutely, #interaction_monthly, #interaction_quarterly, #interaction_secondly, #interaction_weekly, #interaction_yearly
Methods included from Fizzle
#fizzle_match, #fizzle_search, #fizzle_validate
Methods included from Datasources
#datasources, #datasources_by_type
Methods included from Comments
#comments_search, #comments_top
Methods included from Topics
Constructor Details
#initialize(api_key = nil, api_version = nil, options = {}) ⇒ Client
Returns a new instance of Client.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/datarank/client.rb', line 50 def initialize(api_key=nil, api_version=nil, ={}) @api_key = api_key @api_version = api_version ? api_version : "v1"; # defaults [:base_uri] ||= BASE_URI @base_uri = [:base_uri] [:format] ||= :json .each do |k,v| self.class.send k, v end end |
Instance Method Details
#delete(path, options = {}) ⇒ Object
77 78 79 |
# File 'lib/datarank/client.rb', line 77 def delete(path, ={}) http_verb :delete, path, end |
#get(path, options = {}) ⇒ Object
Wrappers for the main HTTP verbs
65 66 67 |
# File 'lib/datarank/client.rb', line 65 def get(path, ={}) http_verb :get, path, end |
#http_verb(verb, path, options = {}) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/datarank/client.rb', line 81 def http_verb(verb, path, ={}) if [:get, :delete].include? verb = {} path = "#{path}?#{URI.encode_www_form()}" if !.empty? else = {body: .to_json} end headers = { 'Authorization' => "Bearer #{@api_key}", "Content-Type" => "application/json", "Accept" => "application/vnd.datarank.#{@api_version}+json" } [:headers] = headers r = self.class.send(verb, path, ) # FIXME: raise errors on actual error packages parsed_json = JSON.parse(r.body) if parsed_json.is_a? Array parsed_json = {objects: parsed_json} end hash = Hashie::Mash.new(parsed_json) raise Error.new(hash.error) if hash.error raise Error.new(hash.errors.join(", ")) if hash.errors hash end |
#post(path, options = {}) ⇒ Object
69 70 71 |
# File 'lib/datarank/client.rb', line 69 def post(path, ={}) http_verb :post, path, end |
#put(path, options = {}) ⇒ Object
73 74 75 |
# File 'lib/datarank/client.rb', line 73 def put(path, ={}) http_verb :put, path, end |