Class: SocialMediaMonitoring::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/social_media_monitoring/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

curl -G -d -is “&api_key=ed08eba2bd5ef47bab6cb1944686fed2&country=de&cat_id=135&geo=53.66,10.1154” api.apphera.com/1/organizations Get a free api_key @ developer.apphera.com



10
11
12
13
14
15
# File 'lib/social_media_monitoring/client.rb', line 10

def initialize(api_key=nil)
  @api_key = api_key
  @api_key ||= SocialMediaMonitoring.api_key
  @api_path = ''

end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/social_media_monitoring/client.rb', line 7

def api_key
  @api_key
end

Instance Method Details

#categories(country) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/social_media_monitoring/client.rb', line 16

def categories(country)
  begin
  results = Mash.new(self.class.get('/categories', :query => {:country => country}.merge(self.default_options)))
rescue => e
  key_error e
end
end

#competitors(cat_id, geo) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/social_media_monitoring/client.rb', line 60

def competitors(cat_id, geo)
  options = {:query => {:cat_id => cat_id, :geo => geo}.merge(self.default_options)}
  begin
    results = Mash.new(self.class.get("/organizations", options))
  rescue => e
    key_error e 
    
  end
end

#create_keyword(keyword) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/social_media_monitoring/client.rb', line 33

def create_keyword(keyword)
  options = {:body => {:keyword => keyword}, :query => self.default_options}
  begin
  results = Mash.new(self.class.post('/keywords/create', options))
rescue => e
  key_error e
end
end

#key_error(mes) ⇒ Object



78
79
80
# File 'lib/social_media_monitoring/client.rb', line 78

def key_error(mes)
  "Invalid key or no Internet connection. Please obtain a free API key at https://developer.apphera.com or try one of the public keys from https://github.com/nikoma/social_media_monitoring, the complete error message is: #{mes}"
end

#keywordsObject



25
26
27
28
29
30
31
# File 'lib/social_media_monitoring/client.rb', line 25

def keywords
  begin
  results = Mash.new(self.class.get('/keywords', :query => self.default_options))
rescue => e
  key_error e
end
end

#reviews(organization_id, review_id = 0) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/social_media_monitoring/client.rb', line 70

def reviews(organization_id, review_id=0)
  options = {:query => {:organization_id => organization_id, :review_id => review_id}.merge(self.default_options)}
  begin
    results = Mash.new(self.class.get("/reviews", options))  
  rescue => e
    key_error e 
  end    
end

#sentiment(body, lang) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/social_media_monitoring/client.rb', line 51

def sentiment(body, lang)
  options = {:body => {:body => body, :lang => lang}, :query => self.default_options}
  begin
  results = Mash.new(self.class.post('/sentiments', options))
rescue => e
  key_error e
end
end

#show_keyword(id) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/social_media_monitoring/client.rb', line 42

def show_keyword(id)
  options = {:query => self.default_options}
  begin
  results = Mash.new(self.class.get("/keywords/#{id}", options))
rescue => e
  key_error e
end
end