sraas 0.4.0 → 0.5.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6eaee146f11038edc1963d62b9854dc350d11c20
4
- data.tar.gz: c04e697ce2763e8538b4352105a41dbd165857a8
2
+ SHA256:
3
+ metadata.gz: d09fea0e576549f83b39b7852ebc1fecdd4b294797359e160dd3a8b9ed041527
4
+ data.tar.gz: bf44025ea2acaed268b8434fae66efd77b7a38b805f910ca73ea17ba44c4cf6f
5
5
  SHA512:
6
- metadata.gz: 1da68d467c235c11bd320f64a95d87b1596916e654a11bb22f34ac71aa44c77435fbc1909176b39206381cf3492a3d42c64c57e69d3b3745c15e424ef2646b6a
7
- data.tar.gz: 6ffd9cfaeb5390e086e3f5befc4345b83f9e8c27facdd47b5ba4de19dda7540f4702ca621e607cbf568ad95d3c49809b3e6b9b05850319c5d80d335085c0cb9b
6
+ metadata.gz: 6e7bad43ba49c2722a0901619bf71718b077787410b4710a07b2540c660af7a947402b3dd790dc23509eeffd580ad5c4f6321e82ae4565d6bf925a16ebe93301
7
+ data.tar.gz: 93360073d28a7b494410046284308110869f163f92c086dbdea4aa5c6d763d65a33c0657ded82dbb17fef46b31f81fadc2cc740974b54954b3c439e7e239eb43
data/README.md CHANGED
@@ -83,7 +83,7 @@ $ sraas cards parents xxxx
83
83
  ## Tests
84
84
  #### Preparation
85
85
  ```bash
86
- $ cd specs/dummy/
86
+ $ cd spec/dummy/
87
87
  $ rake db:migrate
88
88
  ```
89
89
  #### Runing
@@ -1,12 +1,13 @@
1
1
  module Sraas
2
2
  class Configuration
3
- attr_accessor :url, :api_key, :default_deck_name, :default_deck_fingerprint
3
+ attr_accessor :url, :api_key, :default_deck_name, :default_deck_fingerprint, :default_timezone
4
4
 
5
5
  def initialize
6
6
  @url = 'https://www.sraas.io'
7
7
  @api_key = nil
8
8
  @default_deck_name = nil
9
9
  @default_deck_fingerprint = nil
10
+ @default_timezone = :time_zone
10
11
  end
11
12
  end
12
13
  end
@@ -206,7 +206,8 @@ module Sraas
206
206
 
207
207
  # Try all search patterns with name and fingerprint
208
208
  # in case one of them is incorrect, but the other correct
209
- matching_decks = Sraas.template_decks({name_start: name, fingerprint_start: fingerprint})
209
+ matching_decks = name.present? ? Sraas.template_decks({name_start: "#{name} v", fingerprint_start: fingerprint}) : []
210
+ matching_decks = Sraas.template_decks({name_start: name, fingerprint_start: fingerprint}) unless matching_decks.any?
210
211
  matching_decks = Sraas.template_decks({fingerprint_start: fingerprint}) unless matching_decks.any?
211
212
  matching_decks = Sraas.template_decks({name_start: name}) unless matching_decks.any?
212
213
  return false unless matching_decks.any?
@@ -5,13 +5,17 @@ module Sraas
5
5
  # symbol -- the method to call on this object that returns a deck name
6
6
  # nil -- use the default in configuration or errors...
7
7
  # fingerprint: string -- allows locking to one specific deck version
8
- def has_sraas(name: nil, fingerprint: nil, deck: nil)
8
+ # timezone: string -- the timezone to use with Sraas
9
+ # symbol -- the method to call on this object that returns name of timezone field
10
+ # nil -- use the default in configuration or errors...
11
+ def has_sraas(name: nil, fingerprint: nil, deck: nil, timezone: nil)
9
12
  if deck # v1.0 Syntax
10
13
  raise "Since GEM 0.3.0, semantics changed for has_sraas. You need to say has_sraas name: ..."
11
14
  end
12
15
  has_one :sraas, as: :sraas_consumerable, class_name: 'Sraas::Consumer'
13
16
 
14
17
  after_create :configure_sraas_consumer!
18
+ before_update :update_sraas_consumer!
15
19
 
16
20
  if name.is_a?(Symbol)
17
21
  # We allow specifying a symbol as a method name/attribute that will return the deck name
@@ -20,6 +24,14 @@ module Sraas
20
24
  end
21
25
  self.sraas_default_deck_name = name || Sraas.configuration.default_deck_name
22
26
  self.sraas_default_deck_fingerprint = fingerprint || Sraas.configuration.default_deck_fingerprint
27
+
28
+ if timezone.is_a?(Symbol)
29
+ # We allow specifying a symbol as a method name/attribute that will return the name of timezone field
30
+ # make sure model supports it:
31
+ raise "[Undefined Method Error] Class '#{self.name}' doesn't have a method '#{timezone}'" unless self.method_defined?(timezone) || self.has_attribute?(timezone)
32
+ end
33
+ self.sraas_default_timezone = timezone || Sraas.configuration.default_timezone
34
+ Time.find_zone!(self.sraas_default_timezone) unless self.sraas_default_timezone.is_a?(Symbol)
23
35
  end
24
36
  end
25
37
 
@@ -28,6 +40,7 @@ module Sraas
28
40
  base.extend ClassMethods
29
41
  base.cattr_accessor(:sraas_default_deck_name)
30
42
  base.cattr_accessor(:sraas_default_deck_fingerprint)
43
+ base.cattr_accessor(:sraas_default_timezone)
31
44
  end
32
45
 
33
46
  def configure_sraas_consumer!
@@ -67,8 +80,13 @@ module Sraas
67
80
  self.class.sraas_default_deck_fingerprint
68
81
  end
69
82
 
83
+ def consumer_timezone
84
+ timezone = self.class.sraas_default_timezone
85
+ timezone.is_a?(Symbol) ? self.send(timezone) : timezone
86
+ end
87
+
70
88
  def new_consumer
71
- Sraas.sraas_consumer_create(email, tags)
89
+ Sraas.sraas_consumer_create(email, tags, consumer_timezone)
72
90
  end
73
91
 
74
92
  def tags
@@ -78,6 +96,16 @@ module Sraas
78
96
  def user_tag
79
97
  "user_id=#{id}"
80
98
  end
99
+
100
+ def update_sraas_consumer!
101
+ timezone = self.class.sraas_default_timezone
102
+ return unless timezone.is_a?(Symbol)
103
+
104
+ if self.send("#{timezone}_changed?" )
105
+ # update consumer timezone on sraas
106
+ Sraas.sraas_consumer_update_time_zone(sraas.consumer_url, self.send(timezone))
107
+ end
108
+ end
81
109
  end
82
110
  end
83
111
  end
data/lib/sraas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sraas
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.3'
3
3
  end
data/lib/sraas.rb CHANGED
@@ -23,11 +23,16 @@ module Sraas
23
23
  JSON.parse(api_resource(:get, consumer_url))
24
24
  end
25
25
 
26
- def sraas_consumer_create(email, tags = [])
27
- payload = { consumer: { email: email, tags: tags.join(',') } }
26
+ def sraas_consumer_create(email, tags = [], time_zone = 'UTC')
27
+ payload = { consumer: { email: email, tags: tags.join(','), time_zone: time_zone } }
28
28
  JSON.parse(api_resource(:post, consumers_endpoint, payload))
29
29
  end
30
30
 
31
+ def sraas_consumer_update_time_zone(consumer_url, time_zone)
32
+ payload = { consumer: { time_zone: time_zone } }
33
+ JSON.parse(api_resource(:patch, consumer_url, payload))
34
+ end
35
+
31
36
  # This function exists so an admin-like UI
32
37
  # can query many consumer IDs at once
33
38
  # and then access them without creating dozens of requests.
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sraas
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Siegel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-19 00:00:00.000000000 Z
11
+ date: 2021-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rest-client
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: rails
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 5.0.6
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 5.0.6
41
13
  - !ruby/object:Gem::Dependency
42
14
  name: hanami-cli
43
15
  requirement: !ruby/object:Gem::Requirement
@@ -174,24 +146,23 @@ files:
174
146
  homepage: http://no.no/no
175
147
  licenses: []
176
148
  metadata: {}
177
- post_install_message:
149
+ post_install_message:
178
150
  rdoc_options: []
179
151
  require_paths:
180
152
  - lib
181
153
  required_ruby_version: !ruby/object:Gem::Requirement
182
154
  requirements:
183
- - - "~>"
155
+ - - ">="
184
156
  - !ruby/object:Gem::Version
185
- version: '2.3'
157
+ version: '0'
186
158
  required_rubygems_version: !ruby/object:Gem::Requirement
187
159
  requirements:
188
160
  - - ">="
189
161
  - !ruby/object:Gem::Version
190
162
  version: '0'
191
163
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.6.14
194
- signing_key:
164
+ rubygems_version: 3.1.6
165
+ signing_key:
195
166
  specification_version: 4
196
167
  summary: SRAAS.io API Gem
197
168
  test_files: []