muvandy 1.0.2a1
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 +18 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +67 -0
- data/Rakefile +2 -0
- data/lib/muvandy/muvandy.rb +126 -0
- data/lib/muvandy/version.rb +4 -0
- data/lib/muvandy.rb +38 -0
- data/muvandy.gemspec +22 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Aldwin
|
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,67 @@
|
|
1
|
+
# Muvandy
|
2
|
+
|
3
|
+
Client for [Muvandy API](http://muvandy.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'muvandy'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install muvandy
|
18
|
+
|
19
|
+
## To Configure
|
20
|
+
|
21
|
+
Create a file in your config/initializers folder named muvandy_setup.rb (or whichever name you prefer)
|
22
|
+
|
23
|
+
Muvandy.configure do |c|
|
24
|
+
c.api_key = '<place your api key here>'
|
25
|
+
end
|
26
|
+
|
27
|
+
## Get Variations
|
28
|
+
|
29
|
+
### Controller
|
30
|
+
|
31
|
+
Example of using muvandy on a controller.
|
32
|
+
|
33
|
+
class HomeController < ApplicationController
|
34
|
+
include Muvandy
|
35
|
+
before_filter :set_muvandy_info, :only => [:index]
|
36
|
+
|
37
|
+
def index
|
38
|
+
@muvandy = Muvandy.new('experiment-id', :visitor_key => request.remote_ip)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
A 'visitor_key' is required. You can use the visitor's IP address, email or any unique identifier for the user in your app.
|
43
|
+
|
44
|
+
### Views
|
45
|
+
|
46
|
+
<%= content_tag "h1", @muvandy.get_variation("Headline-1", "Greetings!") %>
|
47
|
+
<p>
|
48
|
+
<%= @muvandy.get_variation("main-text-1") %>
|
49
|
+
</p>
|
50
|
+
|
51
|
+
An optional second parameter for 'get_variations' method can be provided to serve as a default value.
|
52
|
+
|
53
|
+
### Conversions
|
54
|
+
|
55
|
+
class HomeController < ApplicationController
|
56
|
+
include Muvandy
|
57
|
+
|
58
|
+
...
|
59
|
+
|
60
|
+
def thank_you
|
61
|
+
|
62
|
+
...
|
63
|
+
|
64
|
+
Muvandy::convert('experiment_id', :visitor_key => request.remote_ip)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
module Muvandy
|
2
|
+
class Muvandy
|
3
|
+
|
4
|
+
include HTTParty
|
5
|
+
format :xml
|
6
|
+
|
7
|
+
def initialize(experiment_id, options={})
|
8
|
+
throw Exception.new("Please configure first.") if Muvandy.api_key.blank?
|
9
|
+
throw Exception.new("No given Experiment ID") if experiment_id.nil?
|
10
|
+
|
11
|
+
@visitor_key = options[:visitor_key] if !options[:visitor_key].blank?
|
12
|
+
|
13
|
+
# For HTTParty
|
14
|
+
self.class.base_uri Muvandy.site
|
15
|
+
self.class.basic_auth Muvandy.api_key, ''
|
16
|
+
|
17
|
+
@experiment_id = experiment_id
|
18
|
+
|
19
|
+
gather_extra_params
|
20
|
+
|
21
|
+
get_all_variable_variations if options[:skip_variations].blank?
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_variation(variable_key, default="")
|
25
|
+
(@variable_variations[variable_key].blank?) ? default : @variable_variations[variable_key].html_safe
|
26
|
+
end
|
27
|
+
|
28
|
+
def convert!(value=50)
|
29
|
+
post(:convert, :value => value)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def get_all_variable_variations
|
35
|
+
@variable_variations = {}
|
36
|
+
begin
|
37
|
+
xml = get(:variable_variations)
|
38
|
+
Rails.logger.debug { "DEBUG ------------ #{xml.parsed_response.inspect}" }
|
39
|
+
if xml.parsed_response && !xml.parsed_response["visitor"].blank?
|
40
|
+
# self.id = xml.parsed_response["visitor"]["id"].to_i if !xml.parsed_response["visitor"].blank? && !xml.parsed_response["visitor"]["id"].blank?
|
41
|
+
xml.parsed_response["visitor"]["variable_variations"]["variable"].each do |v|
|
42
|
+
@variable_variations[v["key"]] = v["value"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def api_prefix
|
50
|
+
"/api/v#{Versionomy.parse(VERSION).major}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def get(action, add_to_query={})
|
54
|
+
query_string = case action
|
55
|
+
when :variable_variations
|
56
|
+
"/experiments/#{@experiment_id}/visitors/variable_variations.xml"
|
57
|
+
end
|
58
|
+
begin
|
59
|
+
xml = self.class.get("#{api_prefix}#{query_string}#{extra_params_to_query(add_to_query)}")
|
60
|
+
raise Exception.new(xml.parsed_response["error"]["message"]) if xml.response.code != 200
|
61
|
+
rescue Exception => e
|
62
|
+
Rails.logger.debug { "Muvandy Gem Error: #{e.message}" }
|
63
|
+
end
|
64
|
+
xml
|
65
|
+
end
|
66
|
+
|
67
|
+
def post(action, query={} )
|
68
|
+
query_string = case action
|
69
|
+
when :convert
|
70
|
+
"/experiments/#{@experiment_id}/visitors/convert.xml"
|
71
|
+
end
|
72
|
+
begin
|
73
|
+
xml = self.class.post("#{api_prefix}#{query_string}", :query => query.merge!(:visitor_key => @visitor_key)) # #{extra_params_to_query(add_to_query)}
|
74
|
+
raise Exception.new(xml.parsed_response["error"]["message"]) if xml.response.code != 200
|
75
|
+
rescue Exception => e
|
76
|
+
Rails.logger.debug { "Muvandy Gem Error: #{e.message}" }
|
77
|
+
end
|
78
|
+
xml
|
79
|
+
end
|
80
|
+
|
81
|
+
def valid_params
|
82
|
+
[ :mode, :visitor_key, :value, :referrer, :utm_term, :utm_campaign, :utm_source, :utm_medium ]
|
83
|
+
end
|
84
|
+
|
85
|
+
def gather_extra_params
|
86
|
+
@extra_params = {}
|
87
|
+
@extra_params[:mode] = Muvandy.mode unless Muvandy.mode.blank?
|
88
|
+
@extra_params[:utm_term] = Muvandy.utm_term unless Muvandy.utm_term.blank?
|
89
|
+
@extra_params[:utm_campaign] = Muvandy.utm_campaign unless Muvandy.utm_campaign.blank?
|
90
|
+
@extra_params[:utm_source] = Muvandy.utm_source unless Muvandy.utm_source.blank?
|
91
|
+
@extra_params[:utm_medium] = Muvandy.utm_medium unless Muvandy.utm_medium.blank?
|
92
|
+
@extra_params[:visitor_key] = @visitor_key unless @visitor_key.blank? #Muvandy.visitor_key.blank?
|
93
|
+
@extra_params[:referrer] = Muvandy.referrer unless Muvandy.referrer.blank?
|
94
|
+
end
|
95
|
+
|
96
|
+
def extra_params_to_query(add_to_query={})
|
97
|
+
return '' if @extra_params.blank?
|
98
|
+
|
99
|
+
query = []
|
100
|
+
params = @extra_params.merge(add_to_query)
|
101
|
+
valid_params.each do |key|
|
102
|
+
query << "#{key}=#{params[key]}" unless params[key].blank?
|
103
|
+
end
|
104
|
+
(query.empty?) ? '' : "?#{query.join('&')}"
|
105
|
+
end
|
106
|
+
|
107
|
+
class << self
|
108
|
+
attr_accessor :api_key,
|
109
|
+
:site,
|
110
|
+
:visitor_key,
|
111
|
+
:referrer,
|
112
|
+
:mode,
|
113
|
+
:utm_term,
|
114
|
+
:utm_campaign,
|
115
|
+
:utm_source,
|
116
|
+
:utm_medium
|
117
|
+
|
118
|
+
def convert(experiment_id, options={})
|
119
|
+
muvandy = Muvandy.new(experiment_id, options.merge(:skip_variations => true))
|
120
|
+
muvandy.convert!
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
data/lib/muvandy.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "muvandy/version"
|
3
|
+
require "muvandy/muvandy"
|
4
|
+
|
5
|
+
module Muvandy
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.send(:include, ClassMethods)
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def set_muvandy_info
|
14
|
+
Muvandy.mode = params[:mode]
|
15
|
+
Muvandy.utm_term = params[:utm_term]
|
16
|
+
Muvandy.utm_campaign = params[:utm_campaign]
|
17
|
+
Muvandy.utm_source = params[:utm_source]
|
18
|
+
Muvandy.utm_medium = params[:utm_medium]
|
19
|
+
|
20
|
+
Muvandy.referrer = request.referrer
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
class << self
|
26
|
+
|
27
|
+
attr_accessor :api_key, :site
|
28
|
+
|
29
|
+
def configure
|
30
|
+
yield self
|
31
|
+
|
32
|
+
Muvandy.api_key = api_key
|
33
|
+
Muvandy.site = (site.nil?) ? 'http://muvandy.com' : site
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/muvandy.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/muvandy/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Aldwin Ibuna"]
|
6
|
+
gem.email = ["aibuna@gmail.com"]
|
7
|
+
gem.description = %q{Client for Muvandy API}
|
8
|
+
gem.summary = %q{Client for Muvandy API}
|
9
|
+
gem.homepage = "https://github.com/muvandy/muvandy"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "muvandy"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.add_runtime_dependency(%q<httparty>, ["~> 0.8"])
|
17
|
+
gem.add_runtime_dependency(%q<versionomy>, ["~> 0.4.3"])
|
18
|
+
gem.version = Muvandy::VERSION
|
19
|
+
|
20
|
+
gem.platform = Gem::Platform::RUBY
|
21
|
+
gem.rubyforge_project = 'muvandy'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: muvandy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2a1
|
5
|
+
prerelease: 5
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Aldwin Ibuna
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: &70272925842020 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.8'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70272925842020
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: versionomy
|
27
|
+
requirement: &70272925836180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.4.3
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70272925836180
|
36
|
+
description: Client for Muvandy API
|
37
|
+
email:
|
38
|
+
- aibuna@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- LICENSE
|
46
|
+
- README.md
|
47
|
+
- Rakefile
|
48
|
+
- lib/muvandy.rb
|
49
|
+
- lib/muvandy/muvandy.rb
|
50
|
+
- lib/muvandy/version.rb
|
51
|
+
- muvandy.gemspec
|
52
|
+
homepage: https://github.com/muvandy/muvandy
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>'
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.3.1
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: muvandy
|
72
|
+
rubygems_version: 1.8.17
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: Client for Muvandy API
|
76
|
+
test_files: []
|