social_media_monitoring 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in social_media_monitoring.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Nikolai Manek
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # SocialMediaMonitoring
2
+
3
+ SocialMediaMonitoring is a collection of API methods of the Apphera API. At this time it offers sentiment analysis and keyword tracking for Google search rankings.
4
+ The API is currently in BETA. I will add more methods and documentation soon.
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'social_media_monitoring'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install social_media_monitoring
18
+
19
+ ## Basic usage
20
+
21
+ Sentiment Analysis
22
+
23
+ require 'social_media_monitoring'
24
+ client = SocialMediaMonitoring::Client.new("987634f072b7c51db349bda9fd5cd6da")
25
+ => #<SocialMediaMonitoring::Client:0x007fa19422d390 @api_key="987634f072b7c51db349bda9fd5cd6da", @api_path="">
26
+
27
+ sentiment = client.sentiment("I love Ruby!","en")
28
+ => <Mash response=<Mash polarity=1 sentiment=0.325>>
29
+ or
30
+ sentiment = client.sentiment("amore","it")
31
+ => <Mash response=<Mash polarity=1 sentiment=0.325>>
32
+
33
+ The sentiment analyzer returns a Mash which you can read like this:
34
+ sentiment.response.polarity
35
+ => 1
36
+ sentiment.response.sentiment
37
+ => 0.325
38
+
39
+ At this time the API supports the following languages:
40
+ English (en)
41
+ German (de)
42
+ Italian (it)
43
+ Spanish (es)
44
+ French (fr)
45
+ Turk (tr)
46
+
47
+
48
+ Keyword tracking
49
+
50
+ require 'social_media_monitoring'
51
+ client = SocialMediaMonitoring::Client.new("987634f072b7c51db349bda9fd5cd6da")
52
+ => #<SocialMediaMonitoring::Client:0x007fa19422d390 @api_key="987634f072b7c51db349bda9fd5cd6da", @api_path="">
53
+
54
+ client.create_keyword("Ruby rulez")
55
+ => <Mash response=<Mash first_check="2012-07-02T23:36:32+00:00" id=553 keyword="Ruby rulez">>
56
+
57
+ It responds with the keyword id, keyword and a date which tells you when you should expect results. The rankings will be updated frequently and
58
+ the history is stored. This allows you to track keyword positions in search results over time.
59
+
60
+ client.keywords
61
+
62
+ => returns a Mash with keywords you are tracking
63
+
64
+ client.show_keyword(553) #id of keyword
65
+
66
+ => returns current and historic rankings
67
+
68
+ The search results are paginated
69
+
70
+ You can get a free API key at https://developer.apphera.com
71
+
72
+
73
+ ## Contributing
74
+
75
+ 1. Fork it
76
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
77
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
78
+ 4. Push to the branch (`git push origin my-new-feature`)
79
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'mash'
3
+ require 'mash'
4
+ gem 'httparty'
5
+ require 'httparty'
6
+
7
+
8
+ class APIKeyNotSet < StandardError; end
9
+
10
+ module SocialMediaMonitoring
11
+
12
+ # Get your API key from https://developer.apphera.com
13
+ def self.api_key
14
+ raise APIKeyNotSet if @api_key.nil?
15
+ @api_key
16
+ end
17
+
18
+ def self.api_key=(api_key)
19
+ @api_key = api_key
20
+ end
21
+
22
+ end
23
+
24
+ directory = File.expand_path(File.dirname(__FILE__))
25
+
26
+ require File.join(directory, 'social_media_monitoring', 'client')
@@ -0,0 +1,44 @@
1
+ module SocialMediaMonitoring
2
+ class Client
3
+ include HTTParty
4
+ base_uri 'https://api.apphera.com/1'
5
+ format :json
6
+
7
+ attr_reader :api_key
8
+
9
+ # Get a free api_key @ https://developer.apphera.com
10
+ def initialize(api_key=nil)
11
+ @api_key = api_key
12
+ @api_key ||= SocialMediaMonitoring.api_key
13
+ @api_path = ''
14
+
15
+ end
16
+
17
+ def keywords
18
+ results = Mash.new(self.class.get('/keywords', :query => self.default_options))
19
+ end
20
+
21
+ def create_keyword(keyword)
22
+ options = {:body => {:keyword => keyword}, :query => self.default_options}
23
+ results = Mash.new(self.class.post('/keywords/create', options))
24
+ end
25
+
26
+ def show_keyword(id)
27
+ options = {:query => self.default_options}
28
+ results = Mash.new(self.class.get("/keywords/#{id}", options))
29
+ end
30
+
31
+ def sentiment(body, lang)
32
+ options = {:body => {:body => body, :lang => lang}, :query => self.default_options}
33
+ results = Mash.new(self.class.post('/sentiments', options))
34
+ end
35
+
36
+
37
+ protected
38
+
39
+ def default_options
40
+ {:api_key => @api_key}
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,3 @@
1
+ module SocialMediaMonitoring
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/social_media_monitoring/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Nikolai Manek"]
6
+ gem.email = ["niko.manek@gmail.com"]
7
+ gem.description = %q{Offers sentiment analysis and search engine keyword tracking}
8
+ gem.summary = %q{Keyword tracking, sentiment analysis}
9
+ gem.homepage = "https://github.com/nikoma/social_media_monitoring"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "social_media_monitoring"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = SocialMediaMonitoring::VERSION
17
+
18
+ gem.add_runtime_dependency "httparty"
19
+ gem.add_runtime_dependency "mash"
20
+ end
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'vcr'
4
+ require 'webmock'
5
+ require 'social_media_monitoring'
6
+
7
+
8
+ VCR.configure do |c|
9
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
10
+ c.hook_into :webmock
11
+
12
+ end
13
+
14
+ class VCRTest < Test::Unit::TestCase
15
+ $client = SocialMediaMonitoring::Client.new("987634f072b7c51db349bda9fd5cd6da")
16
+
17
+ def test_keywords
18
+ VCR.use_cassette('keywords') do
19
+ response = $client.keywords.response.first.name
20
+ assert_match /berliner bubbletea/, response
21
+ end
22
+ end
23
+
24
+ def test_create_keyword
25
+ VCR.use_cassette('create_keyword') do
26
+ keyword = "ruby testing"
27
+ response = $client.create_keyword(keyword).response.keyword
28
+ assert_match keyword, response
29
+ end
30
+ end
31
+
32
+ def test_show_keyword
33
+ VCR.use_cassette('show_keyword') do
34
+ keyword_id = 550
35
+ response = $client.show_keyword(keyword_id).first[1][0].keyword
36
+ assert_match /berliner bubbletea/, response
37
+ end
38
+ end
39
+
40
+ def test_sentiment
41
+ VCR.use_cassette('sentiment') do
42
+ sample = "I love ruby"
43
+ response = $client.sentiment(sample, "en").response.polarity
44
+ assert_equal 1, response.to_i
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.apphera.com/1/keywords/create?api_key=987634f072b7c51db349bda9fd5cd6da
6
+ body:
7
+ encoding: UTF-8
8
+ string: keyword=ruby%20testing
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - nginx/1.2.1
17
+ Date:
18
+ - Wed, 01 Aug 2012 22:11:58 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '90'
23
+ Connection:
24
+ - keep-alive
25
+ Status:
26
+ - 200 OK
27
+ X-Ua-Compatible:
28
+ - IE=Edge,chrome=1
29
+ Etag:
30
+ - ! '"627d44222eb29df3eb988c5faeac89c7"'
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ X-Request-Id:
34
+ - 017c4e8c78ec7037eb77b5dfcb4232d0
35
+ X-Runtime:
36
+ - '0.508844'
37
+ X-Rack-Cache:
38
+ - invalidate, pass
39
+ body:
40
+ encoding: UTF-8
41
+ string: ! '{"response":{"keyword":"ruby testing","id":551,"first_check":"2012-08-02T22:11:58+00:00"}}'
42
+ http_version:
43
+ recorded_at: Wed, 01 Aug 2012 22:12:02 GMT
44
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.apphera.com/1/keywords?api_key=987634f072b7c51db349bda9fd5cd6da
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - nginx/1.2.1
17
+ Date:
18
+ - Wed, 01 Aug 2012 22:00:38 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '357'
23
+ Connection:
24
+ - keep-alive
25
+ Status:
26
+ - 200 OK
27
+ X-Ua-Compatible:
28
+ - IE=Edge,chrome=1
29
+ Etag:
30
+ - ! '"5a65190ea6aaeb838d0f0dd84f2a7ac3"'
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ X-Request-Id:
34
+ - a1669fc9fc6c1de25912d33fdd5604d7
35
+ X-Runtime:
36
+ - '0.010338'
37
+ X-Rack-Cache:
38
+ - miss
39
+ body:
40
+ encoding: UTF-8
41
+ string: ! '{"response":[{"created_at":"2012-08-01T06:19:50Z","id":550,"name":"berliner
42
+ bubbletea","updated_at":"2012-08-01T06:19:50Z"},{"created_at":"2012-08-01T06:19:50Z","id":550,"name":"berliner
43
+ bubbletea","updated_at":"2012-08-01T06:19:50Z"},{"created_at":"2012-08-01T06:19:50Z","id":550,"name":"berliner
44
+ bubbletea","updated_at":"2012-08-01T06:19:50Z"}],"count":3}'
45
+ http_version:
46
+ recorded_at: Wed, 01 Aug 2012 22:00:42 GMT
47
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.apphera.com/1/sentiments?api_key=987634f072b7c51db349bda9fd5cd6da
6
+ body:
7
+ encoding: UTF-8
8
+ string: body=I%20love%20ruby&lang=en
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - nginx/1.2.1
17
+ Date:
18
+ - Wed, 01 Aug 2012 22:20:42 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '45'
23
+ Connection:
24
+ - keep-alive
25
+ Status:
26
+ - 200 OK
27
+ X-Ua-Compatible:
28
+ - IE=Edge,chrome=1
29
+ Etag:
30
+ - ! '"12c84abae49f81af5a943c98c44b2dc0"'
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ X-Request-Id:
34
+ - 08340f5e00add1d1e0e58e48e17a55e7
35
+ X-Runtime:
36
+ - '0.005529'
37
+ X-Rack-Cache:
38
+ - invalidate, pass
39
+ body:
40
+ encoding: UTF-8
41
+ string: ! '{"response":{"polarity":1,"sentiment":0.325}}'
42
+ http_version:
43
+ recorded_at: Wed, 01 Aug 2012 22:20:46 GMT
44
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.apphera.com/1/keywords/550?api_key=987634f072b7c51db349bda9fd5cd6da
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: OK
14
+ headers:
15
+ Server:
16
+ - nginx/1.2.1
17
+ Date:
18
+ - Wed, 01 Aug 2012 22:27:36 GMT
19
+ Content-Type:
20
+ - application/json; charset=utf-8
21
+ Content-Length:
22
+ - '2091'
23
+ Connection:
24
+ - keep-alive
25
+ Status:
26
+ - 200 OK
27
+ X-Ua-Compatible:
28
+ - IE=Edge,chrome=1
29
+ Etag:
30
+ - ! '"8e28eeb0a477fd94ac515e8acd413792"'
31
+ Cache-Control:
32
+ - max-age=0, private, must-revalidate
33
+ X-Request-Id:
34
+ - 57caf318cb134b44241ae14d8df336f1
35
+ X-Runtime:
36
+ - '1.030111'
37
+ X-Rack-Cache:
38
+ - miss
39
+ body:
40
+ encoding: UTF-8
41
+ string: ! '{"response":[{"date":"2012-08-01T06:21:35+00:00","keyword_id":550,"keyword":"berliner
42
+ bubbletea","results":[{"ranking":1,"link_text":"Bubble''s Tea Bar - Mitte,
43
+ Berlin - Bubble Tea","link":"http://www.qype.com/place/1774041-Bubbles-Tea-Bar-Berlin"},{"ranking":2,"link_text":"Bubble
44
+ Tea in Berlin | Tipps auf Qype","link":"http://www.qype.com/de300-berlin/categories/1354-bubble-tea-in-berlin"},{"ranking":3,"link_text":"Bubble
45
+ Tea in Berlin: Die besten L\u00e4den f\u00fcrs Kultgetr\u00e4nk | berlin blog","link":"http://berlin.germanblogs.de/archive/2011/08/03/bubble-tea-in-berlin-die-besten-laeden-fuers-kultgetraenk.htm"},{"ranking":4,"link_text":"boobuk
46
+ - the bubble tea | Bubble Tea: der Tee mit Bubbles","link":"http://www.boobuk.com/"},{"ranking":5,"link_text":"Der
47
+ Bubble Tea Fun-Drink aus Fernost \u00bb BOBOQ","link":"http://www.boboq.de/"},{"ranking":6,"link_text":"Was
48
+ ist gef\u00e4hrlich an Bubble Tea? - Berliner Zeitung","link":"http://www.berliner-zeitung.de/gesundheit/warnungen-vor-modegetraenk-was-ist-gefaehrlich-an-bubble-tea-,10839396,16141164.html"},{"ranking":7,"link_text":"Berlin
49
+ - Alle Bubble-Tea Shops | teabubble.de Bubble Tea","link":"http://www.teabubble.de/bubble-tea-shop-ort/Berlin"},{"ranking":8,"link_text":"Bubble
50
+ O - Bubble Tea and Frozen Yogurt Oranienstra\u00dfe ... - Berlin","link":"http://berlin.kauperts.de/eintrag/Bubble-O-Bubble-Tea-and-Frozen-Yogurt-Oranienstrasse-38-10999-Berlin"},{"ranking":9,"link_text":"Bilder
51
+ zu berliner bubbletea","link":null},{"ranking":10,"link_text":"Krankenkasse
52
+ warnt vor Modegetr\u00e4nk Bubble Tea - Berlin.de","link":"http://www.berlin.de/special/gesundheit-und-beauty/ernaehrung/2523592-215-krankenkasse-warnt-vor-modegetraenk-bubb.html"},{"ranking":11,"link_text":"Bubble
53
+ Tea in Berlin? (laden, Cafe)","link":"http://www.gutefrage.net/frage/bubble-tea-in-berlin"}],"id":"W7-kbR0gSAi-Ihq3K47HrQ","_score":1.0,"_type":"results","_index":"ranks","_version":null,"sort":null,"highlight":null,"_explanation":null}],"count":1,"pagination":{"previous":null,"next":null,"current":1,"per_page":10,"count":1,"pages":1}}'
54
+ http_version:
55
+ recorded_at: Wed, 01 Aug 2012 22:27:40 GMT
56
+ recorded_with: VCR 2.2.4
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social_media_monitoring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Nikolai Manek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mash
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Offers sentiment analysis and search engine keyword tracking
47
+ email:
48
+ - niko.manek@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/social_media_monitoring.rb
59
+ - lib/social_media_monitoring/client.rb
60
+ - lib/social_media_monitoring/version.rb
61
+ - social_media_monitoring.gemspec
62
+ - test/client_test.rb
63
+ - test/fixtures/vcr_cassettes/create_keyword.yml
64
+ - test/fixtures/vcr_cassettes/keywords.yml
65
+ - test/fixtures/vcr_cassettes/sentiment.yml
66
+ - test/fixtures/vcr_cassettes/show_keyword.yml
67
+ homepage: https://github.com/nikoma/social_media_monitoring
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.24
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Keyword tracking, sentiment analysis
91
+ test_files:
92
+ - test/client_test.rb
93
+ - test/fixtures/vcr_cassettes/create_keyword.yml
94
+ - test/fixtures/vcr_cassettes/keywords.yml
95
+ - test/fixtures/vcr_cassettes/sentiment.yml
96
+ - test/fixtures/vcr_cassettes/show_keyword.yml