commission_junction_stats 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/commission_junction_stats.gemspec +17 -0
- data/lib/commission_junction_stats.rb +57 -0
- data/lib/commission_junction_stats/version.rb +3 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Jason Sommerset
|
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,29 @@
|
|
1
|
+
# CommissionJunctionStats
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'commission_junction_stats'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install commission_junction_stats
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/commission_junction_stats/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jason Sommerset"]
|
6
|
+
gem.email = ["jasommerset@gmail.com"]
|
7
|
+
gem.description = "Commission Junction Site Stats using API at https://commission-detail.api.cj.com/v3/commissions"
|
8
|
+
gem.summary = "Commission Junction cj.com Site Stats total by period and by advertiser using API at https://commission-detail.api.cj.com/v3/commissions"
|
9
|
+
gem.homepage = "https://github.com/jasommerset/commission_junction_stats"
|
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 = "commission_junction_stats"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = CommissionJunctionStats::VERSION
|
17
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "commission_junction_stats/version"
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
class CommissionJunctionStats
|
7
|
+
|
8
|
+
attr_reader :total_revenue, :total_revenue_by_advertiser
|
9
|
+
|
10
|
+
# Your code goes here...
|
11
|
+
def initialize (authorization_token, start_date, end_date)
|
12
|
+
|
13
|
+
@total_revenue = 0
|
14
|
+
@total_revenue_by_advertiser = Hash.new
|
15
|
+
|
16
|
+
# set-up API calls
|
17
|
+
uri = "https://commission-detail.api.cj.com/v3/commissions"
|
18
|
+
uri = URI.parse( uri )
|
19
|
+
uri.query = "date-type=event&start-date=" + start_date + "&end-date=" + end_date
|
20
|
+
|
21
|
+
http = Net::HTTP.new( uri.host, uri.port )
|
22
|
+
http.use_ssl = true
|
23
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
24
|
+
|
25
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
26
|
+
request["Authorization"] = authorization_token
|
27
|
+
|
28
|
+
begin
|
29
|
+
|
30
|
+
res, data = http.request(request)
|
31
|
+
|
32
|
+
#TODO catch 500 response codes --- if res.code
|
33
|
+
|
34
|
+
doc = Nokogiri::XML(data)
|
35
|
+
|
36
|
+
set = doc.xpath("//commissions/commission/commission-amount")
|
37
|
+
set.each do |amount|
|
38
|
+
# add to hash
|
39
|
+
@total_revenue += amount.text.to_f
|
40
|
+
end
|
41
|
+
|
42
|
+
by_ad = doc.xpath("//commissions/commission")
|
43
|
+
by_ad.each do |commission|
|
44
|
+
# add to hash
|
45
|
+
(@total_revenue_by_advertiser[commission.xpath('advertiser-name').text.to_s] ||= []) << commission.xpath('commission-amount').text.to_f
|
46
|
+
end
|
47
|
+
|
48
|
+
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError,
|
49
|
+
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e
|
50
|
+
|
51
|
+
puts e.to_s
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commission_junction_stats
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jason Sommerset
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-25 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Commission Junction Site Stats using API at https://commission-detail.api.cj.com/v3/commissions
|
15
|
+
email:
|
16
|
+
- jasommerset@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- commission_junction_stats.gemspec
|
27
|
+
- lib/commission_junction_stats.rb
|
28
|
+
- lib/commission_junction_stats/version.rb
|
29
|
+
homepage: https://github.com/jasommerset/commission_junction_stats
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.24
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Commission Junction cj.com Site Stats total by period and by advertiser using
|
53
|
+
API at https://commission-detail.api.cj.com/v3/commissions
|
54
|
+
test_files: []
|