sraas 0.4.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
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: b62d189168e60dd23ea170f8e3df02e9779609843c3265f1ee69c750726a9cf0
4
+ data.tar.gz: 349b35aeff3fcee321a9dd908f533a3239b3186c7c8059a4913e1d07f0cd41f6
5
5
  SHA512:
6
- metadata.gz: 1da68d467c235c11bd320f64a95d87b1596916e654a11bb22f34ac71aa44c77435fbc1909176b39206381cf3492a3d42c64c57e69d3b3745c15e424ef2646b6a
7
- data.tar.gz: 6ffd9cfaeb5390e086e3f5befc4345b83f9e8c27facdd47b5ba4de19dda7540f4702ca621e607cbf568ad95d3c49809b3e6b9b05850319c5d80d335085c0cb9b
6
+ metadata.gz: 7b6b6de20d42c8944c24e541b6e391b30c12365af68b360f427e26f814263ca526658471a14427ba63ab7d4e84319196eb2e1bb1481046831037a84f4a86710a
7
+ data.tar.gz: 3412e6fcc09d5755f95ea0eaf9640f57b4cf7637054b6d67f2fd03878b41d51894ce7e35416a5e9dbca638a496b7b3a7d3d4f4507343025d8e72527f01181640
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.2'
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,14 +1,14 @@
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.2
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
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -174,7 +174,7 @@ files:
174
174
  homepage: http://no.no/no
175
175
  licenses: []
176
176
  metadata: {}
177
- post_install_message:
177
+ post_install_message:
178
178
  rdoc_options: []
179
179
  require_paths:
180
180
  - lib
@@ -189,9 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
189
  - !ruby/object:Gem::Version
190
190
  version: '0'
191
191
  requirements: []
192
- rubyforge_project:
193
- rubygems_version: 2.6.14
194
- signing_key:
192
+ rubygems_version: 3.1.6
193
+ signing_key:
195
194
  specification_version: 4
196
195
  summary: SRAAS.io API Gem
197
196
  test_files: []