perfecta 0.1.0

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,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Gary Rafferty
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,66 @@
1
+ # Perfecta
2
+
3
+ Ruby client for the Perfect Audience [reporting
4
+ api](https://www.perfectaudience.com/docs#data_api_autoopen)
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'perfecta'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install perfecta
19
+
20
+ ## Usage
21
+
22
+ ### Create a new instance of the Perfecta Client
23
+
24
+ ```ruby
25
+ client = Perfecta::Client.new do |c|
26
+ c.email = 'email@ddress'
27
+ c.password = 'password'
28
+ end
29
+ ```
30
+
31
+ This will exchange the credentials for an API token and use this token
32
+ for all subsequent calls.
33
+
34
+ You can now use the client instance to query the API.
35
+
36
+ ### List all Campaign Reports
37
+
38
+ ```ruby
39
+ p client.campaign_reports.inspect
40
+ ```
41
+
42
+ ### List all Ad Reports
43
+
44
+ ```ruby
45
+ p client.ad_reports.inspect
46
+ ```
47
+
48
+ ### List all Conversion Reports
49
+
50
+ ```ruby
51
+ p client.conversion_reports.inspect
52
+ ```
53
+
54
+ ## TODO
55
+
56
+ 1. Flesh out the rest of the API
57
+ 2. Error handling, specifically for when token expires
58
+ 3. Relationships and delegation between of objects
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs.push "lib"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
@@ -0,0 +1,7 @@
1
+ module Perfecta
2
+ class AdReport < ApiResource
3
+ def initialize attrs
4
+ super attrs
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module Perfecta
2
+ class ApiResource
3
+ def initialize attrs
4
+ attrs.each do |name, val|
5
+ instance_variable_set "@#{name}", val
6
+
7
+ define_singleton_method name.to_sym do
8
+ instance_variable_get "@#{name}"
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ module Perfecta
2
+ class CampaignReport < ApiResource
3
+ def initialize attrs
4
+ super attrs
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Perfecta
2
+ class ConversionReport < ApiResource
3
+ def initialize attrs
4
+ super attrs
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Perfecta
2
+ VERSION = "0.1.0"
3
+ end
data/lib/perfecta.rb ADDED
@@ -0,0 +1,72 @@
1
+ require "perfecta/version"
2
+ require "perfecta/api_resource"
3
+ require "perfecta/campaign_report"
4
+ require "perfecta/ad_report"
5
+ require "perfecta/conversion_report"
6
+ require "rest-client"
7
+ require "json"
8
+
9
+ module Perfecta
10
+ class Client
11
+
12
+ BASE_API_PATH = 'https://api.perfectaudience.com'
13
+
14
+ attr_accessor :email, :password, :token
15
+
16
+ def initialize &block
17
+ yield self if block_given?
18
+ @token = exchange_credentials_for_token
19
+ end
20
+
21
+ def campaign_reports
22
+ url = "#{BASE_API_PATH}/reports/campaign_report"
23
+ resp = JSON.parse(RestClient.get(url, {Authorization: @token}))
24
+
25
+ build_collection_of 'CampaignReport', resp['report']
26
+ end
27
+
28
+ def ad_reports
29
+ url = "#{BASE_API_PATH}/reports/ad_report"
30
+ resp = JSON.parse(RestClient.get(url, {Authorization: @token}))
31
+
32
+ build_collection_of 'AdReport', resp['report']
33
+ end
34
+
35
+ def conversion_reports
36
+ url = "#{BASE_API_PATH}/reports/conversion_report"
37
+ resp = JSON.parse(RestClient.get(url, {Authorization: @token}))
38
+
39
+ build_collection_of 'ConversionReport', resp['report']
40
+ end
41
+
42
+ private
43
+
44
+ def exchange_credentials_for_token
45
+ authenticate
46
+ end
47
+
48
+ def authenticate
49
+ url = "#{BASE_API_PATH}/auth"
50
+ data = {email: @email, password: @password}
51
+
52
+ resp = RestClient.post(url, data)
53
+
54
+ json = JSON.parse resp
55
+
56
+ if json['status'] == 200
57
+ json['token']
58
+ end
59
+ end
60
+
61
+ def build_collection_of klass, data
62
+ retval = []
63
+
64
+ data.each do |d|
65
+ obj = Perfecta.const_get(klass.to_sym).new d
66
+ retval << obj
67
+ end
68
+
69
+ retval
70
+ end
71
+ end
72
+ end
data/perfecta.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'perfecta/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "perfecta"
8
+ gem.version = Perfecta::VERSION
9
+ gem.authors = ["Gary Rafferty"]
10
+ gem.email = ["gary.rafferty@gmail.com"]
11
+ gem.description = %q{Ruby API for the PerfectAudience Reporting API}
12
+ gem.summary = %q{Ruby APU for the PerfectAudience Reporting API}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "rest-client"
21
+ gem.add_development_dependency "mocha"
22
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'test_helper'
2
+
3
+ class AdReportTest < MiniTest::Unit::TestCase
4
+
5
+ describe 'AdReport' do
6
+
7
+ before do
8
+ @attrs = {ad_name: 'Ad 1', ad_id: 123}
9
+ @report = Perfecta::AdReport.new @attrs
10
+ end
11
+
12
+ it 'should be created from a hash' do
13
+ @report.must_be_instance_of Perfecta::AdReport
14
+ end
15
+
16
+ it 'should set the values for each property' do
17
+ @report.ad_name.must_equal 'Ad 1'
18
+ @report.ad_id.must_equal 123
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'test_helper'
2
+
3
+ class CampaignReportTest < MiniTest::Unit::TestCase
4
+
5
+ describe 'CampaignReport' do
6
+
7
+ before do
8
+ @attrs = {name: 'Report 1', campaign_id: 123}
9
+ @report = Perfecta::CampaignReport.new @attrs
10
+ end
11
+
12
+ it 'should be created from a hash' do
13
+ @report.must_be_instance_of Perfecta::CampaignReport
14
+ end
15
+
16
+ it 'should set the values for each property' do
17
+ @report.name.must_equal 'Report 1'
18
+ @report.campaign_id.must_equal 123
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'test_helper'
2
+
3
+ class ConversionReportTest < MiniTest::Unit::TestCase
4
+
5
+ describe 'ConversionReport' do
6
+
7
+ before do
8
+ @attrs = {conversion_name: 'Conversion 1', conversion_id: 123}
9
+ @report = Perfecta::ConversionReport.new @attrs
10
+ end
11
+
12
+ it 'should be created from a hash' do
13
+ @report.must_be_instance_of Perfecta::ConversionReport
14
+ end
15
+
16
+ it 'should set the values for each property' do
17
+ @report.conversion_name.must_equal 'Conversion 1'
18
+ @report.conversion_id.must_equal 123
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,33 @@
1
+ require_relative 'test_helper'
2
+
3
+ class PerfectaTest < MiniTest::Unit::TestCase
4
+
5
+ describe 'Perfecta client' do
6
+
7
+ before do
8
+ Perfecta::Client
9
+ .any_instance
10
+ .stubs(:exchange_credentials_for_token)
11
+ .returns('token')
12
+
13
+ @client = Perfecta::Client.new do |c|
14
+ c.email = 'email@ddress'
15
+ c.password = 'password'
16
+ end
17
+ end
18
+
19
+ it 'is initialized with an email and password' do
20
+ @client.must_be_instance_of Perfecta::Client
21
+ end
22
+
23
+ it "sets the email and password vars" do
24
+ @client.email.must_equal 'email@ddress'
25
+ @client.password.must_equal 'password'
26
+ end
27
+
28
+ it "should authenticate and set the token" do
29
+ @client.token.wont_be_nil
30
+ @client.token.must_equal 'token'
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__),'..','lib'))
2
+
3
+ require 'minitest/spec'
4
+ require 'minitest/autorun'
5
+ require 'mocha/setup'
6
+ require 'perfecta'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: perfecta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Gary Rafferty
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
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: mocha
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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: Ruby API for the PerfectAudience Reporting API
47
+ email:
48
+ - gary.rafferty@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/perfecta.rb
59
+ - lib/perfecta/ad_report.rb
60
+ - lib/perfecta/api_resource.rb
61
+ - lib/perfecta/campaign_report.rb
62
+ - lib/perfecta/conversion_report.rb
63
+ - lib/perfecta/version.rb
64
+ - perfecta.gemspec
65
+ - test/ad_report_test.rb
66
+ - test/campaign_report_test.rb
67
+ - test/conversion_report_test.rb
68
+ - test/perfecta_test.rb
69
+ - test/test_helper.rb
70
+ homepage: ''
71
+ licenses: []
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 1.8.23
91
+ signing_key:
92
+ specification_version: 3
93
+ summary: Ruby APU for the PerfectAudience Reporting API
94
+ test_files:
95
+ - test/ad_report_test.rb
96
+ - test/campaign_report_test.rb
97
+ - test/conversion_report_test.rb
98
+ - test/perfecta_test.rb
99
+ - test/test_helper.rb