talkable 0.9.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Y2MzNjExMDczNTIxNjUwMzA4YWNjYTY1M2MzMzg2Y2M1NDAyM2YxNg==
4
+ MTU1MWNmY2U2ZjE2NTEwODA0NWNhYzc4NmI2ZTVhNWIyOWRjNGRhZg==
5
5
  data.tar.gz: !binary |-
6
- NTdmZTFiYTIwNzZhNDJmNjhhOWVlNmJkZWQwNzNhYTc2MGNhMTk4Mw==
6
+ ZmQ5ZWFmMzYyMWYxY2NjMzcxNTc5YjczNGYwNTYxNmYwMGY4OWI2OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NmNlMGVjMWRiOTZhZTMzOTZhMjZhNGI0ODBhYzRmYzczYjdlOGZkOTg3NDE1
10
- NDg3ODIyMzBiMGFhMzMxMzZmMjQ0NTA0NWQ3MWQyOGE5YTFiZTdiZmU1MjVj
11
- MGJlYmJjMWFkNzk3M2MwZmZhZjRlNzdjNTQwNDA2MjViNmVhMzA=
9
+ ZWQ5NjIwM2U4ZTYyMWUzNzMxYjkwMDc3YWM2MmJlZWEwOGYxMGNhYjYxNjkw
10
+ YTQxMzU1ODQxOTc1NzA4NWYyNWE1NjBmZTc3ZDhlMzQ2ZmEyYjNlOTE0ZDhl
11
+ ZjE0Zjg3YmFjYTJjOTc0ZTA0OGY0OTMxNTJmNGI2NDhmZTIyOWM=
12
12
  data.tar.gz: !binary |-
13
- OTBjZDU2NDJhYzYzZWU5NGMxOTZmZGNkMzhmM2NkMjMzODY0ODQzMDg5NDU5
14
- M2I0ZjNmNzk0YWVjN2ViNzc2MmIyMDRjMDYxZGZjODc0ZWE5YjUxMTc4YWM3
15
- OTExYzhhOTYzZGI1N2Q4Nzk0YjQyZWZiNmY0NWQ3ODNhOGJiYWI=
13
+ Zjc2OTczMjFjYjljMjk5NTQ4Y2EwYzRkZjljNTNiNWJjNWQ4OTFiN2RjZjQ5
14
+ MWMzN2JjZWIwNzJiNjZkMmY2ZjU2YzVlYmIzMmRiM2YzYzJiMDIzNzUxODI1
15
+ Mjc0YzM5MmZkNDYyMDg1NGRhY2NjM2RhNjA4ZDJmMzc4ZGE0Zjk=
data/.gitignore CHANGED
@@ -42,7 +42,7 @@ build-iPhoneSimulator/
42
42
 
43
43
  # for a library or gem, you might want to ignore these files since the code is
44
44
  # intended to run in multiple environments; otherwise, check them in:
45
- # Gemfile.lock
45
+ Gemfile.lock
46
46
  .ruby-version
47
47
  .ruby-gemset
48
48
 
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in testic.gemspec
3
+ # Specify your gem's dependencies in talkable.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -101,7 +101,7 @@ class ApplicationController < ActionController::Base
101
101
  protected
102
102
 
103
103
  def load_talkable_offer
104
- origin = Talkable.register_affiliate_member(campaign_tags: 'popup')
104
+ origin = Talkable.register_affiliate_member
105
105
  @offer ||= origin.offer if origin
106
106
  end
107
107
 
@@ -113,7 +113,10 @@ or invite page at specific path
113
113
  ```ruby
114
114
  class InviteController < ApplicationController
115
115
  def show
116
- origin = Talkable.register_affiliate_member(campaign_tags: 'invite')
116
+ # Make sure you have configured Campaign Placements at Talkable site
117
+ # or explicitly specify campaign tags
118
+ # origin = Talkable.register_affiliate_member(campaign_tags: 'invite')
119
+ origin = Talkable.register_affiliate_member
117
120
  @offer = origin.offer if origin
118
121
  end
119
122
  end
@@ -8,6 +8,7 @@ require 'talkable/railtie' if defined? ::Rails::Railtie
8
8
 
9
9
  module Talkable
10
10
  UUID = 'talkable_visitor_uuid'.freeze
11
+ CURRENT_URL = 'talkable_current_url'.freeze
11
12
 
12
13
  class << self
13
14
  def configure(config = nil)
@@ -27,17 +28,27 @@ module Talkable
27
28
  Thread.current[UUID] = uuid
28
29
  end
29
30
 
30
- def with_uuid(uuid)
31
+ def find_or_generate_uuid
32
+ visitor_uuid || Talkable::API::Visitor.create[:uuid]
33
+ end
34
+
35
+ def current_url
36
+ Thread.current[CURRENT_URL]
37
+ end
38
+
39
+ def current_url=(url)
40
+ Thread.current[CURRENT_URL] = url
41
+ end
42
+
43
+ def with_uuid_and_url(uuid, url)
44
+ old_url, Talkable.current_url = Talkable.current_url, url
31
45
  old_uuid, Talkable.visitor_uuid = Talkable.visitor_uuid, uuid
32
46
  yield if block_given?
33
47
  ensure
48
+ Talkable.current_url = old_url
34
49
  Talkable.visitor_uuid = old_uuid
35
50
  end
36
51
 
37
- def find_or_generate_uuid
38
- visitor_uuid || Talkable::API::Visitor.create[:uuid]
39
- end
40
-
41
52
  end
42
53
 
43
54
  end
@@ -29,7 +29,7 @@ RUBY
29
29
  protected
30
30
 
31
31
  def load_talkable_offer
32
- origin = Talkable.register_affiliate_member(campaign_tags: 'popup')
32
+ origin = Talkable.register_affiliate_member
33
33
  @offer ||= origin.offer if origin
34
34
  end
35
35
  RUBY
@@ -2,7 +2,10 @@ class InviteController < ApplicationController
2
2
  skip_before_action :load_talkable_offer # skip default trigger widget integration
3
3
 
4
4
  def show
5
- origin = Talkable.register_affiliate_member(campaign_tags: 'invite')
5
+ # Make sure you have configured Campaign Placements at Talkable site
6
+ # or explicitly specify campaign tags
7
+ # origin = Talkable.register_affiliate_member(campaign_tags: 'invite')
8
+ origin = Talkable.register_affiliate_member
6
9
  @invite_offer = origin.offer if origin
7
10
  end
8
11
  end
@@ -1,40 +1,29 @@
1
1
  module Talkable
2
- DEFAULT_CAMPAIGN_TAGS = {
3
- Talkable::API::Origin::AFFILIATE_MEMBER => 'invite'.freeze,
4
- Talkable::API::Origin::PURCHASE => 'post-purchase'.freeze,
5
- Talkable::API::Origin::EVENT => nil,
6
- }.freeze
7
-
8
2
  class << self
9
- def register_affiliate_member(params)
3
+ def register_affiliate_member(params = {})
10
4
  register_origin(Talkable::API::Origin::AFFILIATE_MEMBER, params)
11
5
  end
12
6
 
13
- def register_purchase(params)
7
+ def register_purchase(params = {})
14
8
  register_origin(Talkable::API::Origin::PURCHASE, params)
15
9
  end
16
10
 
17
- def register_event(params)
11
+ def register_event(params = {})
18
12
  register_origin(Talkable::API::Origin::EVENT, params)
19
13
  end
20
14
 
21
15
  private
22
16
 
23
- def register_origin(origin_type, params)
24
- origin_params = default_params(origin_type).merge(params)
17
+ def register_origin(origin_type, params = {})
18
+ origin_params = default_params.merge(params)
25
19
  result = Talkable::API::Origin.create(origin_type, origin_params)
26
20
  origin = Talkable::Origin.parse(result)
27
- if offer = origin.offer
28
- # make sure that explicitly specified tags will be listed first
29
- tags = Array(origin_params[:campaign_tags]) | Array(offer.campaign_tags)
30
- offer.campaign_tags = tags.map(&:to_s).uniq
31
- end
32
21
  origin
33
22
  end
34
23
 
35
- def default_params(origin_type)
24
+ def default_params
36
25
  {
37
- campaign_tags: DEFAULT_CAMPAIGN_TAGS[origin_type]
26
+ r: Talkable.current_url,
38
27
  }
39
28
  end
40
29
  end
@@ -8,9 +8,10 @@ module Talkable
8
8
  end
9
9
 
10
10
  def call(env)
11
- uuid = talkable_visitor_uuid(env)
11
+ request = Rack::Request.new(env)
12
+ uuid = talkable_visitor_uuid(request)
12
13
 
13
- result = Talkable.with_uuid(uuid) do
14
+ result = Talkable.with_uuid_and_url(uuid, request.url) do
14
15
  @app.call(env)
15
16
  end
16
17
 
@@ -24,9 +25,8 @@ module Talkable
24
25
 
25
26
  protected
26
27
 
27
- def talkable_visitor_uuid(env)
28
- req = Rack::Request.new(env)
29
- req.params[UUID] || req.cookies[UUID] || Talkable.find_or_generate_uuid
28
+ def talkable_visitor_uuid(request)
29
+ request.params[UUID] || request.cookies[UUID] || Talkable.find_or_generate_uuid
30
30
  end
31
31
 
32
32
  def inject_uuid_in_cookie(uuid, result)
@@ -1,6 +1,7 @@
1
1
  module Talkable
2
2
  class Offer < Hashie::Mash
3
3
  def self.parse(result_hash)
4
+ return nil unless result_hash && result_hash[:offer] && result_hash[:offer].size > 0
4
5
  offer = self.new(result_hash[:offer])
5
6
  offer.claim_links ||= Hashie::Mash.new(result_hash[:claim_links])
6
7
  offer
@@ -8,8 +9,7 @@ module Talkable
8
9
 
9
10
  def advocate_share_iframe(options = {})
10
11
  show_trigger = !options[:ignore_trigger]
11
- tag = campaign_tags.first
12
- iframe_options = default_iframe_options(tag).merge(options[:iframe] || {})
12
+ iframe_options = default_iframe_options.merge(options[:iframe] || {})
13
13
  url = show_trigger ? Furi.merge(show_url, query: {trigger_enabled: 1}) : show_url
14
14
 
15
15
  snippets = []
@@ -26,10 +26,9 @@ module Talkable
26
26
 
27
27
  protected
28
28
 
29
- def default_iframe_options(tag = nil)
30
- tag ||= SecureRandom.hex(3)
29
+ def default_iframe_options
31
30
  {
32
- container: "talkable-offer-#{tag}",
31
+ container: "talkable-offer",
33
32
  }
34
33
  end
35
34
 
@@ -3,6 +3,7 @@ require 'time'
3
3
  module Talkable
4
4
  class Origin < Hashie::Mash
5
5
  def self.parse(result_hash)
6
+ return nil unless result_hash && result_hash[:origin] && result_hash[:origin].size > 0
6
7
  origin_hash = result_hash[:origin]
7
8
  order_date = (origin_hash ? origin_hash[:order_date] : nil)
8
9
 
@@ -1,3 +1,3 @@
1
1
  module Talkable
2
- VERSION = "0.9.0".freeze
2
+ VERSION = "1.0.0".freeze
3
3
  end
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
5
5
  s.name = "talkable"
6
6
  s.version = Talkable::VERSION
7
7
  s.date = Date.today.to_s
8
- s.summary = "Talkable Referral Programe API"
8
+ s.summary = "Talkable Referral Program API"
9
9
  s.description = "Talkable Ruby Gem to make your own referral program in Sinatra or Rails application"
10
10
  s.authors = ["Talkable"]
11
11
  s.email = "dev@talkable.com"
@@ -17,7 +17,11 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.required_ruby_version = ">= 1.9.3"
19
19
 
20
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
20
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.1.0")
21
+ s.add_dependency "nokogiri", "< 1.7.0"
22
+ end
23
+
24
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.2.2")
21
25
  s.add_dependency "rack", ">= 1.5.2", "< 2"
22
26
  else
23
27
  s.add_dependency "rack", ">= 1.5.2"
@@ -30,8 +34,14 @@ Gem::Specification.new do |s|
30
34
  s.add_development_dependency "rake", "~> 11.2"
31
35
  s.add_development_dependency "rspec", "~> 3.4"
32
36
  s.add_development_dependency "simplecov", "~> 0.12"
33
- s.add_development_dependency "json", "~> 1.8.3" if RUBY_VERSION < '2.0'
34
- s.add_development_dependency "webmock", "~> 2.1"
37
+
38
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.0")
39
+ s.add_development_dependency "json", "~> 1.8.3"
40
+ s.add_development_dependency "webmock", ">= 2.1", "< 2.3"
41
+ else
42
+ s.add_development_dependency "webmock", ">= 2.1"
43
+ end
44
+
35
45
  s.add_development_dependency "ammeter" # specs for generators
36
- s.add_development_dependency "haml" # check haml syntex in generators
46
+ s.add_development_dependency "haml" # check haml syntax in generators
37
47
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: talkable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Talkable
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2017-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - <
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - <
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rack
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -132,16 +146,22 @@ dependencies:
132
146
  name: webmock
133
147
  requirement: !ruby/object:Gem::Requirement
134
148
  requirements:
135
- - - ~>
149
+ - - ! '>='
136
150
  - !ruby/object:Gem::Version
137
151
  version: '2.1'
152
+ - - <
153
+ - !ruby/object:Gem::Version
154
+ version: '2.3'
138
155
  type: :development
139
156
  prerelease: false
140
157
  version_requirements: !ruby/object:Gem::Requirement
141
158
  requirements:
142
- - - ~>
159
+ - - ! '>='
143
160
  - !ruby/object:Gem::Version
144
161
  version: '2.1'
162
+ - - <
163
+ - !ruby/object:Gem::Version
164
+ version: '2.3'
145
165
  - !ruby/object:Gem::Dependency
146
166
  name: ammeter
147
167
  requirement: !ruby/object:Gem::Requirement
@@ -180,7 +200,6 @@ files:
180
200
  - .gitignore
181
201
  - .rspec
182
202
  - Gemfile
183
- - Gemfile.lock
184
203
  - LICENSE
185
204
  - README.md
186
205
  - Rakefile
@@ -236,5 +255,5 @@ rubyforge_project:
236
255
  rubygems_version: 2.4.8
237
256
  signing_key:
238
257
  specification_version: 4
239
- summary: Talkable Referral Programe API
258
+ summary: Talkable Referral Program API
240
259
  test_files: []
@@ -1,126 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- talkable (0.9.0)
5
- furi (~> 0.2)
6
- hashie (~> 3.4)
7
- rack (>= 1.5.2, < 2)
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- actionpack (4.2.7.1)
13
- actionview (= 4.2.7.1)
14
- activesupport (= 4.2.7.1)
15
- rack (~> 1.6)
16
- rack-test (~> 0.6.2)
17
- rails-dom-testing (~> 1.0, >= 1.0.5)
18
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
19
- actionview (4.2.7.1)
20
- activesupport (= 4.2.7.1)
21
- builder (~> 3.1)
22
- erubis (~> 2.7.0)
23
- rails-dom-testing (~> 1.0, >= 1.0.5)
24
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
25
- activesupport (4.2.7.1)
26
- i18n (~> 0.7)
27
- json (~> 1.7, >= 1.7.7)
28
- minitest (~> 5.1)
29
- thread_safe (~> 0.3, >= 0.3.4)
30
- tzinfo (~> 1.1)
31
- addressable (2.4.0)
32
- ammeter (1.1.3)
33
- activesupport (>= 3.0)
34
- railties (>= 3.0)
35
- rspec-rails (>= 2.2)
36
- builder (3.2.2)
37
- crack (0.4.3)
38
- safe_yaml (~> 1.0.0)
39
- diff-lcs (1.2.5)
40
- docile (1.1.5)
41
- erubis (2.7.0)
42
- furi (0.2.0)
43
- haml (4.0.7)
44
- tilt
45
- hashdiff (0.3.0)
46
- hashie (3.4.4)
47
- i18n (0.7.0)
48
- json (1.8.3)
49
- loofah (2.0.3)
50
- nokogiri (>= 1.5.9)
51
- mini_portile2 (2.1.0)
52
- minitest (5.9.0)
53
- nokogiri (1.6.8)
54
- mini_portile2 (~> 2.1.0)
55
- pkg-config (~> 1.1.7)
56
- pkg-config (1.1.7)
57
- rack (1.6.4)
58
- rack-test (0.6.3)
59
- rack (>= 1.0)
60
- rails-deprecated_sanitizer (1.0.3)
61
- activesupport (>= 4.2.0.alpha)
62
- rails-dom-testing (1.0.7)
63
- activesupport (>= 4.2.0.beta, < 5.0)
64
- nokogiri (~> 1.6.0)
65
- rails-deprecated_sanitizer (>= 1.0.1)
66
- rails-html-sanitizer (1.0.3)
67
- loofah (~> 2.0)
68
- railties (4.2.7.1)
69
- actionpack (= 4.2.7.1)
70
- activesupport (= 4.2.7.1)
71
- rake (>= 0.8.7)
72
- thor (>= 0.18.1, < 2.0)
73
- rake (11.2.2)
74
- rspec (3.5.0)
75
- rspec-core (~> 3.5.0)
76
- rspec-expectations (~> 3.5.0)
77
- rspec-mocks (~> 3.5.0)
78
- rspec-core (3.5.1)
79
- rspec-support (~> 3.5.0)
80
- rspec-expectations (3.5.0)
81
- diff-lcs (>= 1.2.0, < 2.0)
82
- rspec-support (~> 3.5.0)
83
- rspec-mocks (3.5.0)
84
- diff-lcs (>= 1.2.0, < 2.0)
85
- rspec-support (~> 3.5.0)
86
- rspec-rails (3.5.2)
87
- actionpack (>= 3.0)
88
- activesupport (>= 3.0)
89
- railties (>= 3.0)
90
- rspec-core (~> 3.5.0)
91
- rspec-expectations (~> 3.5.0)
92
- rspec-mocks (~> 3.5.0)
93
- rspec-support (~> 3.5.0)
94
- rspec-support (3.5.0)
95
- safe_yaml (1.0.4)
96
- simplecov (0.12.0)
97
- docile (~> 1.1.0)
98
- json (>= 1.8, < 3)
99
- simplecov-html (~> 0.10.0)
100
- simplecov-html (0.10.0)
101
- thor (0.19.1)
102
- thread_safe (0.3.5)
103
- tilt (2.0.5)
104
- tzinfo (1.2.2)
105
- thread_safe (~> 0.1)
106
- webmock (2.1.0)
107
- addressable (>= 2.3.6)
108
- crack (>= 0.3.2)
109
- hashdiff
110
-
111
- PLATFORMS
112
- ruby
113
-
114
- DEPENDENCIES
115
- ammeter
116
- bundler (~> 1.12)
117
- haml
118
- json (~> 1.8.3)
119
- rake (~> 11.2)
120
- rspec (~> 3.4)
121
- simplecov (~> 0.12)
122
- talkable!
123
- webmock (~> 2.1)
124
-
125
- BUNDLED WITH
126
- 1.12.5