Class: FacebookTopics::Api
- Inherits:
-
Object
- Object
- FacebookTopics::Api
- Includes:
- HTTParty
- Defined in:
- lib/facebook_topics/api.rb
Instance Attribute Summary collapse
-
#api_version ⇒ Object
Returns the value of attribute api_version.
-
#auth_token ⇒ Object
Returns the value of attribute auth_token.
Instance Method Summary collapse
- #feeds(topic_id, fields = [], options = {}) ⇒ Object
-
#initialize(attrs) ⇒ Api
constructor
A new instance of Api.
- #insights(contains_all, opts = {}) ⇒ Object
- #quick(topic, fields = [], options = {}) ⇒ Object
- #search(query, fields = []) ⇒ Object
Constructor Details
#initialize(attrs) ⇒ Api
Returns a new instance of Api.
9 10 11 12 13 14 |
# File 'lib/facebook_topics/api.rb', line 9 def initialize(attrs) @auth_token = attrs.delete(:auth_token) @api_version = attrs.delete(:api_version) self.class.default_params access_token: @auth_token end |
Instance Attribute Details
#api_version ⇒ Object
Returns the value of attribute api_version.
7 8 9 |
# File 'lib/facebook_topics/api.rb', line 7 def api_version @api_version end |
#auth_token ⇒ Object
Returns the value of attribute auth_token.
7 8 9 |
# File 'lib/facebook_topics/api.rb', line 7 def auth_token @auth_token end |
Instance Method Details
#feeds(topic_id, fields = [], options = {}) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/facebook_topics/api.rb', line 40 def feeds(topic_id, fields = [], = {}) fields = ["ranked_posts"] + fields q = {fields: fields.flatten.uniq.join(',')} q.merge! FeedCollection.new self.class.get("/#{api_version}/#{topic_id}", {query: q}).parsed_response end |
#insights(contains_all, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/facebook_topics/api.rb', line 51 def insights(contains_all, opts = {} ) from_date = opts.delete(:from_date) until_date = opts.delete(:until_date) region = opts.delete(:region) city = opts.delete(:city) country = opts.delete(:country) continent = opts.delete(:continent) breakdown = opts.delete(:breakdown) fields = "mentions" fields << ".since(#{from_date})" unless from_date.nil? fields << ".until(#{until_date})" unless until_date.nil? fields << ".region(#{region})" if region.present? fields << ".city(#{city})" if city.present? fields << ".country(#{country})" if country.present? fields << ".continent(#{continent})" if continent.present? fields << ".breakdown_by(#{breakdown.reject(&:blank?)})" if breakdown.present? q = {contains_all: [contains_all], fields: fields} data = Insight.new self.class.get("/#{api_version}/topic_insights", {query: q}).parsed_response data.breakdown.each { |d| d["date"] = {from_date: from_date, until_date: until_date}.stringify_keys } return data end |
#quick(topic, fields = [], options = {}) ⇒ Object
31 32 33 34 |
# File 'lib/facebook_topics/api.rb', line 31 def quick(topic, fields = [], = {}) topic_id = search(topic, fields).first.id feeds(topic_id, fields, ) end |
#search(query, fields = []) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/facebook_topics/api.rb', line 20 def search(query, fields = []) q = {q: query, type: 'topic'} q.merge!(fields: fields.join(',')) unless fields.empty? TopicCollection.new self.class.get("/#{api_version}/search", {query: q})["data"] end |