whoa 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.md +120 -0
- data/Rakefile +57 -0
- data/VERSION +1 -0
- data/lib/whoa.rb +25 -0
- data/lib/whoa/authentication.rb +29 -0
- data/lib/whoa/experiment.rb +69 -0
- data/lib/whoa/feed.rb +50 -0
- data/lib/whoa/link.rb +10 -0
- data/lib/whoa/page.rb +36 -0
- data/lib/whoa/request.rb +63 -0
- data/lib/whoa/wo_object.rb +91 -0
- data/test/helper.rb +10 -0
- data/test/test_whoa.rb +7 -0
- data/whoa.gemspec +70 -0
- metadata +133 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 richmolj@gmail.com
|
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,120 @@
|
|
1
|
+
Whoa
|
2
|
+
====
|
3
|
+
|
4
|
+
http://github.com/richmolj/whoa
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Simple Active-Recordy API to the Google Website Optimizer (WO) API. Create experiments, start/stop/modify/search them, add/modify pages, get code snippets, etc.
|
10
|
+
|
11
|
+
No Rails required.
|
12
|
+
|
13
|
+
Basic Usage
|
14
|
+
===========
|
15
|
+
|
16
|
+
Authentication
|
17
|
+
--------------
|
18
|
+
|
19
|
+
> Whoa.email = 'xxxxx'
|
20
|
+
> Whoa.password = 'xxxxx'
|
21
|
+
|
22
|
+
Uses ClientLogin. OAuth coming soon.
|
23
|
+
|
24
|
+
Basic actions
|
25
|
+
-------------
|
26
|
+
|
27
|
+
Just think Active Record.
|
28
|
+
|
29
|
+
Create
|
30
|
+
|
31
|
+
> Whoa::Experiment.create(:title => "My New Experiment")
|
32
|
+
|
33
|
+
or
|
34
|
+
|
35
|
+
> Whoa::Experiment.new
|
36
|
+
> Whoa::Experiment.title = "My New Experiment"
|
37
|
+
> Whoa::Experiment.save
|
38
|
+
|
39
|
+
Update
|
40
|
+
|
41
|
+
> Whoa::Experiment.update_attributes(:title => "My new title")
|
42
|
+
|
43
|
+
Read
|
44
|
+
|
45
|
+
> Whoa::Experiment.all(:status => "Running")
|
46
|
+
> Whoa::Experiment.first(:title => "Foo")
|
47
|
+
> Whoa::Experiment.find(123456)
|
48
|
+
|
49
|
+
If you're wondering what you can get/set, take a look at the WO API docs. You also have the handy #attributes method.
|
50
|
+
|
51
|
+
Delete:
|
52
|
+
|
53
|
+
> Whoa::Experiment.first.destroy
|
54
|
+
|
55
|
+
Experiments and Pages get a nice #to_xml method as well, though it won't include all attributes (see TODO)
|
56
|
+
|
57
|
+
Experiments
|
58
|
+
-----------
|
59
|
+
|
60
|
+
Some handy shortcuts:
|
61
|
+
|
62
|
+
> @experiment.copy!
|
63
|
+
> @experiment.start!
|
64
|
+
> @experiment.stop!
|
65
|
+
|
66
|
+
Each experiment has #tracking\_script, #control\_script and #conversion_script. You'll need to inject this code into your pages somehow to get experiments working.
|
67
|
+
|
68
|
+
Note that unlike the manual WO setup, the API doesn't validate your live site for tracking code. This is actually pretty handy, since you can inject code and start experiments independent of each other depending on your workflow.
|
69
|
+
|
70
|
+
Pages
|
71
|
+
-----
|
72
|
+
|
73
|
+
Experiments have many pages; each page belongs to an experiment.
|
74
|
+
|
75
|
+
> @experiment.pages.first
|
76
|
+
> @experiment.create_page(:title => "foo", :content => "bar")
|
77
|
+
|
78
|
+
Requirements
|
79
|
+
------------
|
80
|
+
|
81
|
+
* rest-client 0.4.2
|
82
|
+
* happymapper >= 0.3.0
|
83
|
+
* active_support >= 2.2.0
|
84
|
+
|
85
|
+
TODO
|
86
|
+
----
|
87
|
+
|
88
|
+
* OAuth
|
89
|
+
* Right now, this only works for A/B experiments, not multivariate
|
90
|
+
* Validations could be better handled
|
91
|
+
* Defining what you can get/set is a bit murky.
|
92
|
+
* Some additional API corner cases and AR-like sugar
|
93
|
+
* Testing. It's open-source, I slacked.
|
94
|
+
* Haven't bothered with trying other versions of dependencies. I'm almost positive you'd get away with an older verison of ActiveSupport.
|
95
|
+
|
96
|
+
License
|
97
|
+
-------
|
98
|
+
|
99
|
+
Copyright (c) 2009 richmolj@gmail.com
|
100
|
+
|
101
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
102
|
+
a copy of this software and associated documentation files (the
|
103
|
+
"Software"), to deal in the Software without restriction, including
|
104
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
105
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
106
|
+
permit persons to whom the Software is furnished to do so, subject to
|
107
|
+
the following conditions:
|
108
|
+
|
109
|
+
The above copyright notice and this permission notice shall be
|
110
|
+
included in all copies or substantial portions of the Software.
|
111
|
+
|
112
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
113
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
114
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
115
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
116
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
117
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
118
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
119
|
+
|
120
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "whoa"
|
8
|
+
gem.summary = %Q{Active-Recordy API to the Google Website Optimizer API (WO)}
|
9
|
+
gem.description = %Q{Basic CRUD actions through an AR-style interface. Start/Stop experiments, get tracking snippets, add pages, etc.}
|
10
|
+
gem.email = "lrichmond@customink.com"
|
11
|
+
gem.homepage = "http://github.com/richmolj/whoa"
|
12
|
+
gem.authors = ["richmolj@gmail.com"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
|
15
|
+
gem.add_dependency "happymapper", ">= 0.3.0"
|
16
|
+
gem.add_dependency "rest-client", ">= 1.4.2"
|
17
|
+
gem.add_dependency "active_support", ">= 2.3.0"
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/test_*.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/test_*.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
task :test => :check_dependencies
|
46
|
+
|
47
|
+
task :default => :test
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "whoa #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/lib/whoa.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'net/https'
|
5
|
+
|
6
|
+
require 'happymapper'
|
7
|
+
require 'rest_client'
|
8
|
+
|
9
|
+
require 'whoa/wo_object'
|
10
|
+
require 'whoa/link'
|
11
|
+
require 'whoa/page'
|
12
|
+
require 'whoa/experiment'
|
13
|
+
require 'whoa/authentication'
|
14
|
+
require 'whoa/feed'
|
15
|
+
require 'whoa/request'
|
16
|
+
|
17
|
+
module Whoa
|
18
|
+
|
19
|
+
class << self
|
20
|
+
attr_accessor :email
|
21
|
+
attr_accessor :password
|
22
|
+
attr_accessor :account_id
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Whoa
|
2
|
+
class Authentication
|
3
|
+
class AuthError < StandardError;end
|
4
|
+
|
5
|
+
Url = 'https://www.google.com/accounts/ClientLogin'
|
6
|
+
|
7
|
+
def parameters
|
8
|
+
{
|
9
|
+
'Email' => Whoa.email,
|
10
|
+
'Passwd' => Whoa.password,
|
11
|
+
'accountType' => 'GOOGLE',
|
12
|
+
'service' => 'analytics',
|
13
|
+
'source' => 'whoa-001'
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def send_request
|
18
|
+
RestClient.post(Url, parameters) do |response|
|
19
|
+
raise AuthError unless response.code == 200
|
20
|
+
response.return!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def auth_token
|
25
|
+
send_request.body.match(/^Auth=(.*)$/)[1]
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Whoa
|
2
|
+
class Experiment < WoObject
|
3
|
+
|
4
|
+
Url = "https://www.google.com/analytics/feeds/websiteoptimizer/experiments"
|
5
|
+
|
6
|
+
tag 'entry'
|
7
|
+
element :wo_url, String, :tag => "id"
|
8
|
+
element :updated, Time
|
9
|
+
element :title, String
|
10
|
+
|
11
|
+
with_options :namespace => "http://schemas.google.com/analytics/websiteoptimizer/2009" do |exp|
|
12
|
+
exp.element :account_id, Integer, :tag => "analyticsAccountId"
|
13
|
+
exp.element :control_script, String, :tag => "controlScript"
|
14
|
+
exp.element :conversion_script, String, :tag => "conversionScript"
|
15
|
+
exp.element :tracking_script, String, :tag => "trackingScript"
|
16
|
+
exp.element :experiment_id, Integer, :tag => "experimentId"
|
17
|
+
exp.element :type, String, :tag => "experimentType"
|
18
|
+
exp.element :ab_experiment_count, Integer, :tag => "numAbPageVariations"
|
19
|
+
exp.element :combination_count, Integer, :tag => "numCombinations"
|
20
|
+
exp.element :status, String
|
21
|
+
end
|
22
|
+
|
23
|
+
has_many :links, Whoa::Link
|
24
|
+
|
25
|
+
def pages
|
26
|
+
Whoa::Feed.all_pages(experiment_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_page(opts)
|
30
|
+
opts.merge!({:experiment_id => experiment_id})
|
31
|
+
Whoa::Page.create(opts)
|
32
|
+
end
|
33
|
+
|
34
|
+
def stop!
|
35
|
+
update_attributes(:status => 'Finished')
|
36
|
+
end
|
37
|
+
|
38
|
+
def start!
|
39
|
+
update_attributes(:status => 'Running')
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.find(exp_id)
|
43
|
+
Whoa::Request.get(url(exp_id)) do |response|
|
44
|
+
return if response.code == 401 # raise like AR? I say no.
|
45
|
+
parse(response.body)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def url
|
50
|
+
str = Url
|
51
|
+
str += "/#{experiment_id}" unless new_record?
|
52
|
+
str
|
53
|
+
end
|
54
|
+
|
55
|
+
# TODO: remove all default account stuff
|
56
|
+
def to_xml
|
57
|
+
Whoa::Request.build_payload do |xml|
|
58
|
+
xml.title title
|
59
|
+
xml.gwo :experimentType, 'AB'
|
60
|
+
xml.gwo :status, status
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def all
|
65
|
+
Feed.all.experiments
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/lib/whoa/feed.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Whoa
|
2
|
+
class Feed
|
3
|
+
include HappyMapper
|
4
|
+
|
5
|
+
ListExperimentsUrl = "https://www.google.com/analytics/feeds/websiteoptimizer/experiments"
|
6
|
+
|
7
|
+
tag 'feed'
|
8
|
+
|
9
|
+
has_many :experiments, Whoa::Experiment
|
10
|
+
has_many :pages, Whoa::Page
|
11
|
+
|
12
|
+
def self.all
|
13
|
+
Whoa::Request.get(ListExperimentsUrl) do |response|
|
14
|
+
parse(response.body)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# TODO: can probably be handled more eloquently combined with mm (extract_options!),
|
19
|
+
# or remove the mm altogether.
|
20
|
+
def self.all_pages(exp_id)
|
21
|
+
Whoa::Request.get(experiment_pages_url(exp_id)) do |response|
|
22
|
+
parse(response.body).pages
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.experiment_pages_url(exp_id)
|
27
|
+
"#{ListExperimentsUrl}/#{exp_id}/abpagevariations"
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.method_missing(id, *args, &blk)
|
31
|
+
if id.to_s =~ /^all_/
|
32
|
+
assoc = id.to_s.gsub("all_","")
|
33
|
+
return all.send(assoc) if args.first.blank?
|
34
|
+
|
35
|
+
selection_statements = returning Array.new do |stmts|
|
36
|
+
args.first.each_pair do |key, value|
|
37
|
+
stmts << "self.#{key}.to_s == '#{value.to_s}'"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
all.send(assoc).select do |assoc|
|
42
|
+
assoc.instance_eval selection_statements.join(" && ")
|
43
|
+
end
|
44
|
+
else
|
45
|
+
super
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
data/lib/whoa/link.rb
ADDED
data/lib/whoa/page.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Whoa
|
2
|
+
class Page < WoObject
|
3
|
+
|
4
|
+
tag 'entry'
|
5
|
+
element :wo_url, String, :tag => 'id'
|
6
|
+
element :updated, Time
|
7
|
+
element :edited, Time, :namespace => 'http://www.w3.org/2007/app'
|
8
|
+
element :title, String
|
9
|
+
element :content, String
|
10
|
+
element :variation_id, String, :tag => 'abPageVariationId', :namespace => 'http://schemas.google.com/analytics/websiteoptimizer/2009'
|
11
|
+
|
12
|
+
has_many :links, Whoa::Link
|
13
|
+
|
14
|
+
def experiment_id
|
15
|
+
@experiment_id ||= (wo_url.to_s.split("experiments/")[1].split("/")[0].to_i if wo_url)
|
16
|
+
end
|
17
|
+
|
18
|
+
def experiment_id=(val)
|
19
|
+
@experiment_id = val
|
20
|
+
end
|
21
|
+
|
22
|
+
def url
|
23
|
+
str = "https://www.google.com/analytics/feeds/websiteoptimizer/experiments/#{experiment_id}/abpagevariations"
|
24
|
+
str += "/#{variation_id}" unless new_record?
|
25
|
+
str
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_xml
|
29
|
+
Whoa::Request.build_payload do |xml|
|
30
|
+
xml.title title
|
31
|
+
xml.content content
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/whoa/request.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
module Whoa
|
2
|
+
class Request
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def auth_token
|
7
|
+
@auth_token ||= Whoa::Authentication.new.auth_token
|
8
|
+
end
|
9
|
+
|
10
|
+
def headers
|
11
|
+
@headers ||=
|
12
|
+
{
|
13
|
+
:content_type => "application/atom+xml",
|
14
|
+
'Authorization' => "GoogleLogin auth=#{auth_token}"
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def namespaces
|
19
|
+
{
|
20
|
+
:base => 'http://www.w3.org/2005/Atom',
|
21
|
+
:gwo => 'http://schemas.google.com/analytics/websiteoptimizer/2009',
|
22
|
+
:app => 'http://www.w3.org/2007/app',
|
23
|
+
:gd => 'http://schemas.google.com/g/2005'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_xml_namespaces
|
28
|
+
returning Hash.new do |hash|
|
29
|
+
namespaces.each_pair do |key, value|
|
30
|
+
hash.merge!({"xmlns#{':'+key.to_s unless key == :base}" => value})
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_payload
|
36
|
+
xml = Builder::XmlMarkup.new
|
37
|
+
|
38
|
+
xml.entry(build_xml_namespaces) do
|
39
|
+
yield xml
|
40
|
+
xml.gwo :analyticsAccountId, Whoa.account_id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def send_to_wo(verb, url, payload=nil)
|
45
|
+
args = verb.to_s =~ /(post|put)/ ? [url, payload, headers] : [url, headers]
|
46
|
+
RestClient.send(verb, *args) do |resp|
|
47
|
+
yield resp
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# For http verbs
|
52
|
+
def method_missing(id, *args, &blk)
|
53
|
+
if id.to_s =~ /^(get|post|put|delete)/
|
54
|
+
send_to_wo(id, *args, &blk)
|
55
|
+
else
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module Whoa
|
2
|
+
class WoObject
|
3
|
+
attr_accessor :new_record
|
4
|
+
|
5
|
+
def self.inherited(subclass)
|
6
|
+
subclass.send :include, HappyMapper
|
7
|
+
end
|
8
|
+
|
9
|
+
# TODO: hack. should add some protection so wo_url can't be set manually
|
10
|
+
# Or some other new record magic.
|
11
|
+
def initialize(opts={})
|
12
|
+
self.new_record = true
|
13
|
+
merge_attributes(opts)
|
14
|
+
end
|
15
|
+
|
16
|
+
def merge_attributes(opts)
|
17
|
+
opts.each_pair do |key, value|
|
18
|
+
self.send("#{key}=", value)
|
19
|
+
end
|
20
|
+
self
|
21
|
+
end
|
22
|
+
alias_method :attributes=, :merge_attributes
|
23
|
+
|
24
|
+
# e.g. Whoa::Feed.all_experiments
|
25
|
+
def self.all(opts={})
|
26
|
+
Whoa::Feed.send("all_#{name.split("::").last.downcase.pluralize}", opts)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.first(opts={})
|
30
|
+
all(opts).last
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.last(opts={})
|
34
|
+
all(opts).last
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.create(opts={})
|
38
|
+
obj = new(opts)
|
39
|
+
obj.new_record = true
|
40
|
+
obj.save
|
41
|
+
end
|
42
|
+
|
43
|
+
def update_attributes(opts={})
|
44
|
+
merge_attributes(opts)
|
45
|
+
save
|
46
|
+
end
|
47
|
+
|
48
|
+
def copy!
|
49
|
+
self.new_record = true
|
50
|
+
self.wo_url = nil
|
51
|
+
save
|
52
|
+
end
|
53
|
+
|
54
|
+
def save
|
55
|
+
verb = new_record? ? :post : :put
|
56
|
+
Whoa::Request.send(verb, url, to_xml) do |response|
|
57
|
+
self.new_record = false
|
58
|
+
obj = self.class.handle_response(response)
|
59
|
+
merge_attributes(obj.attributes)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def destroy
|
64
|
+
Whoa::Request.delete(url, to_xml) do |resp|
|
65
|
+
resp.code == 200 ? true : false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Returns a hash of all the attributes with their names as keys and the values of the attributes as values.
|
70
|
+
def attributes
|
71
|
+
self.instance_variable_names.inject({}) do |attrs, name|
|
72
|
+
attrs[name.gsub("@","")] = instance_variable_get(name)
|
73
|
+
attrs
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
# TODO: hacky
|
78
|
+
def new_record?
|
79
|
+
self.new_record && wo_url.nil?
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.handle_response(response)
|
83
|
+
if response.code.to_s !~ /^(200|201)/
|
84
|
+
raise "Not a valid response from WO, was #{CGI.unescapedHTML(response.body)}"
|
85
|
+
else
|
86
|
+
parse(response.body)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_whoa.rb
ADDED
data/whoa.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{whoa}
|
8
|
+
s.version = "0.5.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["richmolj@gmail.com"]
|
12
|
+
s.date = %q{2010-03-21}
|
13
|
+
s.description = %q{Basic CRUD actions through an AR-style interface. Start/Stop experiments, get tracking snippets, add pages, etc.}
|
14
|
+
s.email = %q{lrichmond@customink.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/whoa.rb",
|
27
|
+
"lib/whoa/authentication.rb",
|
28
|
+
"lib/whoa/experiment.rb",
|
29
|
+
"lib/whoa/feed.rb",
|
30
|
+
"lib/whoa/link.rb",
|
31
|
+
"lib/whoa/page.rb",
|
32
|
+
"lib/whoa/request.rb",
|
33
|
+
"lib/whoa/wo_object.rb",
|
34
|
+
"test/helper.rb",
|
35
|
+
"test/test_whoa.rb",
|
36
|
+
"whoa.gemspec"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/richmolj/whoa}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.6}
|
42
|
+
s.summary = %q{Active-Recordy API to the Google Website Optimizer API (WO)}
|
43
|
+
s.test_files = [
|
44
|
+
"test/helper.rb",
|
45
|
+
"test/test_whoa.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
54
|
+
s.add_runtime_dependency(%q<happymapper>, [">= 0.3.0"])
|
55
|
+
s.add_runtime_dependency(%q<rest-client>, [">= 1.4.2"])
|
56
|
+
s.add_runtime_dependency(%q<active_support>, [">= 2.3.0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
59
|
+
s.add_dependency(%q<happymapper>, [">= 0.3.0"])
|
60
|
+
s.add_dependency(%q<rest-client>, [">= 1.4.2"])
|
61
|
+
s.add_dependency(%q<active_support>, [">= 2.3.0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
|
65
|
+
s.add_dependency(%q<happymapper>, [">= 0.3.0"])
|
66
|
+
s.add_dependency(%q<rest-client>, [">= 1.4.2"])
|
67
|
+
s.add_dependency(%q<active_support>, [">= 2.3.0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: whoa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 0
|
9
|
+
version: 0.5.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- richmolj@gmail.com
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-03-21 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: thoughtbot-shoulda
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: happymapper
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
41
|
+
- 3
|
42
|
+
- 0
|
43
|
+
version: 0.3.0
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rest-client
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 1
|
55
|
+
- 4
|
56
|
+
- 2
|
57
|
+
version: 1.4.2
|
58
|
+
type: :runtime
|
59
|
+
version_requirements: *id003
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: active_support
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 2
|
69
|
+
- 3
|
70
|
+
- 0
|
71
|
+
version: 2.3.0
|
72
|
+
type: :runtime
|
73
|
+
version_requirements: *id004
|
74
|
+
description: Basic CRUD actions through an AR-style interface. Start/Stop experiments, get tracking snippets, add pages, etc.
|
75
|
+
email: lrichmond@customink.com
|
76
|
+
executables: []
|
77
|
+
|
78
|
+
extensions: []
|
79
|
+
|
80
|
+
extra_rdoc_files:
|
81
|
+
- LICENSE
|
82
|
+
- README.md
|
83
|
+
files:
|
84
|
+
- .document
|
85
|
+
- .gitignore
|
86
|
+
- LICENSE
|
87
|
+
- README.md
|
88
|
+
- Rakefile
|
89
|
+
- VERSION
|
90
|
+
- lib/whoa.rb
|
91
|
+
- lib/whoa/authentication.rb
|
92
|
+
- lib/whoa/experiment.rb
|
93
|
+
- lib/whoa/feed.rb
|
94
|
+
- lib/whoa/link.rb
|
95
|
+
- lib/whoa/page.rb
|
96
|
+
- lib/whoa/request.rb
|
97
|
+
- lib/whoa/wo_object.rb
|
98
|
+
- test/helper.rb
|
99
|
+
- test/test_whoa.rb
|
100
|
+
- whoa.gemspec
|
101
|
+
has_rdoc: true
|
102
|
+
homepage: http://github.com/richmolj/whoa
|
103
|
+
licenses: []
|
104
|
+
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options:
|
107
|
+
- --charset=UTF-8
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
version: "0"
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
segments:
|
122
|
+
- 0
|
123
|
+
version: "0"
|
124
|
+
requirements: []
|
125
|
+
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.3.6
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Active-Recordy API to the Google Website Optimizer API (WO)
|
131
|
+
test_files:
|
132
|
+
- test/helper.rb
|
133
|
+
- test/test_whoa.rb
|