add_this 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rake_tasks~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.2@add_this --create
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in add_this.gemspec
4
+ gemspec
5
+
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ # Get Those Automated Test
2
+ guard 'rspec', :version => 2 do
3
+ watch(%r{^spec/.+_spec\.rb$})
4
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 General Things Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Add This
2
+
3
+ Ruby wrapper for the [Add This Analytics API](http://www.addthis.com/help/analytics-api#.TzzlN0zC4V).
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ $ gem i add_this
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ With your user_id and password define a configure block that defines them like so:
14
+
15
+ ### Global Config
16
+
17
+ ```ruby
18
+ AddThis.configure do |config|
19
+ config.user_id = "generalthings"
20
+ config.password = "awesome"
21
+ end
22
+ ```
23
+
24
+ ### or Per Request
25
+
26
+ ```ruby
27
+ add_this = AddThis::Client.new(user_id: "generalthings", password: "awesome")
28
+ ```
29
+
30
+ For making requests to the api is quite simple it follows most of the current Add
31
+ This Structure for urls only broken by an underscore so [/shares/day](https://api.addthis.com/analytics/1.0/pub/shares/day.csv)
32
+ would be a method called `shares_day`
33
+
34
+
35
+ ## Example calls
36
+
37
+ You have two ways available to get data one on the AddThis class like so:
38
+
39
+ ```ruby
40
+ AddThis.get.shares_url
41
+ ```
42
+
43
+ or by creating the client and requesting through that like so:
44
+
45
+ ```ruby
46
+ add_this = AddThis::Client.new
47
+ add_this.shares_url
48
+ ```
49
+
50
+ or passing query params you just need to provide a hash into that method as so:
51
+
52
+ ```ruby
53
+ AddThis.get.shares_url({service: "facebook_like"})
54
+ ```
55
+
56
+
57
+ Resources:
58
+
59
+ * [Add This Analytics API](http://www.addthis.com/help/analytics-api#.TzzlN0zC4V)
60
+
61
+
62
+ ## Note on Patches/Pull Requests
63
+
64
+ * Fork the project.
65
+ * Make your feature addition or bug fix.
66
+ * Add tests for it. This is important so I don't break it in a
67
+ future version unintentionally.
68
+ * Commit, do not mess with rakefile, version, or history.
69
+ (if you want to have your own version, that is fine but
70
+ bump version in a commit by itself I can ignore when I pull)
71
+ * Send me a pull request. Bonus points for topic branches.
72
+
73
+ ## Copyright
74
+
75
+ Copyright (c) 2012 General Things Inc. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
8
+
9
+ desc "Open an irb session preloaded with this library"
10
+ task :console do
11
+ sh "irb -rubygems -I lib -I extra -r add_this.rb"
12
+ end
data/add_this.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "add_this/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "add_this"
7
+ s.version = AddThis::VERSION
8
+ s.authors = ["Christopher Hein", "Ryan Van Niekerk", "Nick Hodulik"]
9
+ s.email = ["chris@generalthings.com", "rvanniekerk@generalthings.com", "nick@generalthings.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Simple API connector for getting analytic data from AddThis}
12
+ s.description = %q{Simple API connector for getting analytic data from AddThis}
13
+
14
+ s.rubyforge_project = "add_this"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_runtime_dependency "faraday"
23
+ s.add_runtime_dependency "faraday_middleware"
24
+ s.add_runtime_dependency "hashie"
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "guard"
27
+ s.add_development_dependency "guard-rspec"
28
+ # s.add_runtime_dependency "rest-client"
29
+ end
@@ -0,0 +1,66 @@
1
+ # Client Class
2
+ #
3
+ # builds a base class for all the api calls
4
+ # to inherit from.
5
+
6
+ require "add_this/requests"
7
+
8
+ module AddThis
9
+
10
+ class Client
11
+ # include all other classes to inherit from
12
+ include Requests
13
+
14
+ attr_accessor :user_id, :password
15
+
16
+ # Creating the base client
17
+ #
18
+ # @option opts [String] :user_id login for Add This
19
+ # @option opts [String] :password password for Add This
20
+ #
21
+ # @example
22
+ # AddThis::Client.new
23
+ def initialize(opts = {})
24
+ @user_id = opts[:user_id] || AddThis.configuration.user_id
25
+ @password = opts[:password] || AddThis.configuration.password
26
+ connection.basic_auth(@user_id, @password)
27
+ end
28
+
29
+ # Creates a Faraday connection block
30
+ #
31
+ # @return [Faraday::Connection]
32
+ def connection
33
+ @connection ||= Faraday.new(url: base_url, headers: default_headers, ssl: {verify: false}) do |builder|
34
+ builder.use Faraday::Request::UrlEncoded
35
+ builder.use Faraday::Response::Mashify
36
+ builder.use Faraday::Response::ParseJson
37
+ builder.adapter Faraday.default_adapter
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ # @protected
44
+ def base_url
45
+ "https://api.addthis.com/analytics/1.0/pub/"
46
+ end
47
+
48
+ # @protected
49
+ def default_headers
50
+ {
51
+ accept: 'application/json',
52
+ user_agent: 'Ruby gem',
53
+ }
54
+ end
55
+
56
+ end
57
+
58
+ class << self
59
+ attr_accessor :client
60
+ end
61
+
62
+ def self.get
63
+ self.client ||= Client.new
64
+ end
65
+
66
+ end
@@ -0,0 +1,45 @@
1
+ # Configuration Class
2
+ #
3
+ # this allows to you to setup all your configuration
4
+ # params through an initializer such as:
5
+ #
6
+ # config/initializers/add_this.rb
7
+ #
8
+ # @example
9
+ # AddThis.configure do
10
+ # config.user_id = "generalthings"
11
+ # config.password = "password"
12
+ # end
13
+
14
+ module AddThis
15
+
16
+ class Configuration
17
+
18
+ # Define the available methods
19
+ attr_accessor :user_id, :password
20
+
21
+ def initialize
22
+ @user_id = "generalthings"
23
+ @password = "password"
24
+ end
25
+ end
26
+
27
+ # Defines configuration method to allow
28
+ # Configuration.new to be stored on the
29
+ # global object
30
+ class << self
31
+ attr_accessor :configuration
32
+ end
33
+
34
+ # Allows you to build a configure block
35
+ #
36
+ # @option options [String] :user_id login to Add This
37
+ # @option options [String] :password password to Add This
38
+ # @return [Boolean]
39
+ def self.configure
40
+ self.configuration ||= Configuration.new
41
+ yield configuration
42
+ true
43
+ end
44
+
45
+ end
@@ -0,0 +1,27 @@
1
+ module AddThis
2
+
3
+ module Requests
4
+
5
+ def self.requests(*args)
6
+ args.each do |arg|
7
+ define_method arg do |*options|
8
+ metric, dimension = arg.to_s.split("_")
9
+ connection.get("/analytics/1.0/pub/shares/url.json", options[0]).body
10
+ end
11
+ end
12
+ end
13
+
14
+ requests :shares_day, :shares_url, :shares_domain, :shares_service,
15
+ :shares_interest, :shares_continent, :shares_country, :clicks_day,
16
+ :clicks_url, :clicks_domain, :clicks_service, :clicks_interest,
17
+ :clicks_continent, :clicks_country, :subscriptions_day, :subscriptions_url,
18
+ :subscriptions_domain, :subscriptions_service, :subscriptions_interest,
19
+ :subscriptions_continent, :subscriptions_country, :sharers_day,
20
+ :sharers_interest, :influencers_day, :influencers_interest, :clickers_day,
21
+ :clickers_interest, :users_day, :users_interest, :searches_term,
22
+ :referers_domain
23
+
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,3 @@
1
+ module AddThis
2
+ VERSION = "0.0.1"
3
+ end
data/lib/add_this.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "add_this/version"
4
+ require "add_this/configuration"
5
+ require "add_this/client"
@@ -0,0 +1,99 @@
1
+ require "spec_helper"
2
+
3
+ describe AddThis::Client do
4
+ before(:each) do
5
+ AddThis.configure do |config|
6
+ config.user_id = "chris"
7
+ config.password = "hein"
8
+ end
9
+ end
10
+ let(:client) { AddThis::Client.new }
11
+
12
+ context "instantiation" do
13
+
14
+ it "should have a new method" do
15
+ AddThis::Client.should respond_to :new
16
+ end
17
+
18
+ end
19
+
20
+ context "attrs" do
21
+ let(:client) { AddThis::Client.new({user_id: "chris", password: "hein"}) }
22
+
23
+ it "should have user_id attr" do
24
+ client.should respond_to :user_id
25
+ end
26
+
27
+ it "should have password attr" do
28
+ client.should respond_to :password
29
+ end
30
+
31
+ end
32
+
33
+ context "setting the attributes" do
34
+ let(:params) { { user_id: "chris", password: "password" } }
35
+ let(:client) { AddThis::Client.new(params) }
36
+
37
+ it "should have set the user_id" do
38
+ client.user_id.should eq "chris"
39
+ end
40
+
41
+ it "should have set the password" do
42
+ client.password.should eq "password"
43
+ end
44
+
45
+ end
46
+
47
+ context "loading them from config block" do
48
+
49
+ it "should have set the user_id" do
50
+ client.user_id.should eq "chris"
51
+ end
52
+
53
+ it "should have set the password" do
54
+ client.password.should eq "hein"
55
+ end
56
+
57
+ end
58
+
59
+ context "setting up the connection" do
60
+ let(:connection) { client.connection }
61
+
62
+ it "should respond to connection" do
63
+ client.should respond_to :connection
64
+ end
65
+
66
+ it "should return the base url" do
67
+ client.send(:base_url).should eq "https://api.addthis.com/analytics/1.0/pub/"
68
+ end
69
+
70
+ it "should return a hash for default_headers" do
71
+ client.send(:default_headers).should be_kind_of Hash
72
+ end
73
+
74
+ it "should respond with a faraday connection" do
75
+ connection.should be_kind_of Faraday::Connection
76
+ end
77
+ end
78
+
79
+ context "calling the API with out creating a new client" do
80
+
81
+ it "should respond_to :client" do
82
+ AddThis.should respond_to :client
83
+ end
84
+
85
+ it "should respond_to :get" do
86
+ AddThis.should respond_to :get
87
+ end
88
+
89
+ it "should be able to make trailing requests" do
90
+ AddThis.get.should respond_to :shares_url
91
+ end
92
+
93
+ it "should be a kind of Faraday::Connection" do
94
+ AddThis.get.should be_kind_of AddThis::Client
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -0,0 +1,69 @@
1
+ require "spec_helper"
2
+
3
+ describe AddThis::Configuration do
4
+
5
+ let(:config) { AddThis::Configuration.new }
6
+ let(:configure) do
7
+ AddThis.configure do |config|
8
+ config.user_id = "chris"
9
+ config.password = "hein"
10
+ end
11
+ end
12
+
13
+ context "instantiation" do
14
+
15
+ it "should have a new method" do
16
+ AddThis::Configuration.should respond_to :new
17
+ end
18
+
19
+ it "should return configuration object" do
20
+ configure.should eq true
21
+ end
22
+
23
+ end
24
+
25
+ context "attrs" do
26
+
27
+ it "should have a attr of user_id" do
28
+ config.should respond_to :user_id
29
+ end
30
+
31
+ it "should have an attr of password" do
32
+ config.should respond_to :password
33
+ end
34
+
35
+ end
36
+
37
+ context "getting the attrs" do
38
+
39
+ it "should have access to the configuration variables for user_id" do
40
+ AddThis.configuration.should respond_to :user_id
41
+ end
42
+
43
+ it "should have access to the configuration variables for password" do
44
+ AddThis.configuration.should respond_to :password
45
+ end
46
+
47
+ it "should have chris for user_id" do
48
+ AddThis.configuration.user_id.should eq "chris"
49
+ end
50
+
51
+ it "should have chris for password" do
52
+ AddThis.configuration.password.should eq "hein"
53
+ end
54
+
55
+ end
56
+
57
+ context "base class" do
58
+
59
+ it "should have an attribute of configuration" do
60
+ AddThis.should respond_to :configuration
61
+ end
62
+
63
+ it "should have a method for configure" do
64
+ AddThis.should respond_to :configure
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ class DummyClass; end
4
+
5
+ describe AddThis::Requests do
6
+ let(:klass) { DummyClass.new }
7
+ let(:requests) { klass.extend(AddThis::Requests) }
8
+
9
+ context "instantiation" do
10
+ end
11
+
12
+ context "defining api calls" do
13
+
14
+ it "should respond_to shares_day" do
15
+ requests.should respond_to :shares_day
16
+ end
17
+
18
+ it "should respond_to shares_url" do
19
+ requests.should respond_to :shares_url
20
+ end
21
+
22
+ it "should respond_to shares_domain" do
23
+ requests.should respond_to :shares_domain
24
+ end
25
+
26
+ it "should respond_to shares_service" do
27
+ requests.should respond_to :shares_service
28
+ end
29
+
30
+ it "should respond_to shares_interest" do
31
+ requests.should respond_to :shares_interest
32
+ end
33
+
34
+ it "should respond_to shares_continent" do
35
+ requests.should respond_to :shares_continent
36
+ end
37
+
38
+ it "should respond_to shares_country" do
39
+ requests.should respond_to :shares_country
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe AddThis do
4
+
5
+ it "should have a version set" do
6
+ AddThis::VERSION.should_not eq nil
7
+ end
8
+
9
+ end
@@ -0,0 +1,10 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ require "add_this"
5
+
6
+ RSpec.configure do |config|
7
+
8
+ config.mock_with :rspec
9
+
10
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: add_this
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Christopher Hein
9
+ - Ryan Van Niekerk
10
+ - Nick Hodulik
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2012-02-16 00:00:00.000000000Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: faraday
18
+ requirement: &70284673873900 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70284673873900
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: &70284673873140 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70284673873140
38
+ - !ruby/object:Gem::Dependency
39
+ name: hashie
40
+ requirement: &70284673871800 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *70284673871800
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ requirement: &70284673870500 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *70284673870500
60
+ - !ruby/object:Gem::Dependency
61
+ name: guard
62
+ requirement: &70284673869820 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *70284673869820
71
+ - !ruby/object:Gem::Dependency
72
+ name: guard-rspec
73
+ requirement: &70284673869020 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *70284673869020
82
+ description: Simple API connector for getting analytic data from AddThis
83
+ email:
84
+ - chris@generalthings.com
85
+ - rvanniekerk@generalthings.com
86
+ - nick@generalthings.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - .rvmrc
94
+ - Gemfile
95
+ - Guardfile
96
+ - LICENSE
97
+ - README.md
98
+ - Rakefile
99
+ - add_this.gemspec
100
+ - lib/add_this.rb
101
+ - lib/add_this/client.rb
102
+ - lib/add_this/configuration.rb
103
+ - lib/add_this/requests.rb
104
+ - lib/add_this/version.rb
105
+ - spec/add_this/client_spec.rb
106
+ - spec/add_this/configuration_spec.rb
107
+ - spec/add_this/requests_spec.rb
108
+ - spec/add_this/version_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: ''
111
+ licenses: []
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ none: false
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ! '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project: add_this
130
+ rubygems_version: 1.8.10
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: Simple API connector for getting analytic data from AddThis
134
+ test_files:
135
+ - spec/add_this/client_spec.rb
136
+ - spec/add_this/configuration_spec.rb
137
+ - spec/add_this/requests_spec.rb
138
+ - spec/add_this/version_spec.rb
139
+ - spec/spec_helper.rb
140
+ has_rdoc: