lucid_intercom 0.11.0 → 0.12.0

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
2
  SHA256:
3
- metadata.gz: 0c79fdf9db9290c3f3ce19018e653330829d4ae65d9d651dcc01a3654e38d3a2
4
- data.tar.gz: 75ad290ae14e0f376d61481354be8d0f657975158cc909f6c0d835434a83d211
3
+ metadata.gz: c68b630c07ce2c240795b154f8d5c874db29c516e357582b4f1dcfe8e4504f50
4
+ data.tar.gz: f2f796e2d8e4cea69af445d8a17befa36dec12c7abceed9eaa43172c970b8da8
5
5
  SHA512:
6
- metadata.gz: 51125d01350d54d600663f6be32bf98665bbb7c24f82aeae488fd8fe27b4a6ee0e4e6df0da1fbcf8acccc93f2cd16b627dda81ef2bea6b51b7e2c1e2fcc73c09
7
- data.tar.gz: 0ea00b6f1ae51e1216e349d45cc5be0dd54f0363d1a4da3c952a1a5674ade82b5968b8f129c6472ba4736100cc637e9b9056be6e2a9abb42ef67ea03b11978a7
6
+ metadata.gz: 8a41991df15b5cf39e7e97d9e00fce2380765f96dabe2907fa684b539d3e504de095eb09b0f6c4d7e9e0194245cc7d2127e7816b471de1cae610c363a07a750d
7
+ data.tar.gz: a57a7947ffde3d25d6aa844d8ba1ea16e4e3cacc3ef307751a397d2d0f4df2dde82a2f0538213694446e3127359a5f08c3d2546eb633bf9c509f2b91ee61c98c
data/README.md CHANGED
@@ -14,15 +14,24 @@ Usage
14
14
 
15
15
  ### Configure the default API credentials
16
16
 
17
- LucidIntercom.config = LucidIntercom::Config.new(
18
- '...', # access_token
19
- '...', # secret
20
- '...', # app_id
21
- '...', # app_prefix
22
- 123456 # admin_id
17
+ LucidIntercom.configure(
18
+ access_token: '...',
19
+ admin_id: 123456,
20
+ app_id: '...',
21
+ app_prefix: '...',
22
+ secret: '...',
23
23
  )
24
24
 
25
- Here, ‘app_prefix’ is the snakecased app name, e.g. ‘smart_order_tags
25
+ Here, ‘app_prefix’ is the snakecased app name, e.g. ‘smart_order_tags’.
26
+
27
+ Alternatively load the configuration from a Ruby file. The Ruby
28
+ file is evaluated and should return a hash.
29
+
30
+ LucidIntercom.configure_from_file('config/intercom.rb') # the default path
31
+
32
+ When loading from a file, any environment variables matching the
33
+ upcased key with the prefix ‘INTERCOM_’ will override values in the
34
+ file. For example ‘INTERCOM_APP_ID=...’.
26
35
 
27
36
 
28
37
  ### Render the browser snippet
@@ -34,7 +34,7 @@ module LucidIntercom
34
34
  # @return [Hash]
35
35
  #
36
36
  private def app
37
- prefix = LucidIntercom.app_prefix
37
+ prefix = LucidIntercom.config.app_prefix
38
38
 
39
39
  app_data.each_with_object({}) do |(k, v), h|
40
40
  h["#{prefix}_#{k}"] = v
@@ -1,51 +1,48 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'forwardable'
4
-
5
3
  require 'lucid_intercom'
4
+ require 'lucid_utils'
6
5
 
7
6
  module LucidIntercom
8
7
  NotConfiguredError = Class.new(Error)
9
8
 
10
9
  class << self
11
- extend Forwardable
10
+ #
11
+ # @param options [Hash]
12
+ #
13
+ # @return [Config]
14
+ #
15
+ def configure(options = {})
16
+ @config = Config.new(
17
+ **@config.to_h.compact,
18
+ **options,
19
+ )
20
+ end
12
21
 
13
- def_delegators(
14
- :config,
15
- :access_token,
16
- :secret,
17
- :app_id,
18
- :app_prefix,
19
- :admin_id # for messages/emails
20
- )
22
+ #
23
+ # @param path [String]
24
+ #
25
+ # @return [Config]
26
+ #
27
+ def configure_from_file(path = 'config/intercom.rb')
28
+ options = LucidUtils::ConfigFromFile.new.(path, env_prefix: 'intercom')
21
29
 
22
- # @param config [Config]
23
- attr_writer :config
30
+ configure(options)
31
+ end
24
32
 
25
33
  #
26
34
  # @return [Config]
27
35
  #
28
- # @raise [NotConfiguredError] if config is unset
29
- #
30
36
  def config
31
- raise NotConfiguredError unless @config
32
-
33
- @config
37
+ @config ||= configure
34
38
  end
35
39
  end
36
40
 
37
- class Config
38
- extend Dry::Initializer
39
-
40
- # @return [String]
41
- param :access_token
42
- # @return [String]
43
- param :secret
44
- # @return [String]
45
- param :app_id
46
- # @return [String] the snakecased app name, e.g. 'smart_order_tags'
47
- param :app_prefix
48
- # @return [Integer]
49
- param :admin_id
41
+ class Config < Dry::Struct
42
+ attribute :access_token, Types::String
43
+ attribute :admin_id, Types::Integer
44
+ attribute :app_id, Types::String
45
+ attribute :app_prefix, Types::String # the snakecased app name, e.g. 'smart_order_tags'
46
+ attribute :secret, Types::String
50
47
  end
51
48
  end
@@ -64,7 +64,7 @@ module LucidIntercom
64
64
  # event :changed_plan
65
65
  #
66
66
  def self.event(name)
67
- define_method(:name) { "#{LucidIntercom.app_prefix}_#{name}" }
67
+ define_method(:name) { "#{LucidIntercom.config.app_prefix}_#{name}" }
68
68
 
69
69
  private :name
70
70
  end
@@ -19,7 +19,7 @@ module LucidIntercom
19
19
  #
20
20
  def call(path, data)
21
21
  res = @http.headers(
22
- 'Authorization' => "Bearer #{LucidIntercom.access_token}",
22
+ 'Authorization' => "Bearer #{LucidIntercom.config.access_token}",
23
23
  'Accept' => 'application/json',
24
24
  'Content-Type' => 'application/json'
25
25
  ).post("https://api.intercom.io/#{path}", json: data)
@@ -32,7 +32,7 @@ module LucidIntercom
32
32
  #
33
33
  private def unauthenticated_settings
34
34
  {
35
- app_id: LucidIntercom.app_id,
35
+ app_id: LucidIntercom.config.app_id,
36
36
  }
37
37
  end
38
38
 
@@ -24,7 +24,7 @@ module LucidIntercom
24
24
  template: 'plain',
25
25
  from: {
26
26
  type: 'admin',
27
- id: LucidIntercom.admin_id,
27
+ id: LucidIntercom.config.admin_id,
28
28
  },
29
29
  to: {
30
30
  type: 'user',
@@ -21,7 +21,7 @@ module LucidIntercom
21
21
  body: body,
22
22
  from: {
23
23
  type: 'admin',
24
- id: LucidIntercom.admin_id,
24
+ id: LucidIntercom.config.admin_id,
25
25
  },
26
26
  to: {
27
27
  type: 'user',
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LucidIntercom
4
+ module Types
5
+ include Dry.Types(default: :strict)
6
+ end
7
+ end
@@ -43,7 +43,7 @@ module LucidIntercom
43
43
  # @return [String]
44
44
  #
45
45
  private def user_hash(email)
46
- OpenSSL::HMAC.hexdigest('sha256', LucidIntercom.secret, email)
46
+ OpenSSL::HMAC.hexdigest('sha256', LucidIntercom.config.secret, email)
47
47
  end
48
48
  end
49
49
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LucidIntercom
4
- VERSION = '0.11.0'
4
+ VERSION = '0.12.0'
5
5
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dry/initializer'
4
+ require 'dry/struct'
4
5
 
5
6
  module LucidIntercom
6
7
  autoload :Attributes, 'lucid_intercom/attributes.rb'
@@ -19,7 +20,10 @@ module LucidIntercom
19
20
  autoload :Response, 'lucid_intercom/response.rb'
20
21
  autoload :SendEmail, 'lucid_intercom/send_email.rb'
21
22
  autoload :SendMessage, 'lucid_intercom/send_message.rb'
23
+ autoload :Types, 'lucid_intercom/types.rb'
22
24
  autoload :UpdateUser, 'lucid_intercom/update_user.rb'
23
25
  autoload :UserAttributes, 'lucid_intercom/user_attributes.rb'
24
26
  autoload :VERSION, 'lucid_intercom/version.rb'
25
27
  end
28
+
29
+ require 'lucid_intercom/config'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucid_intercom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelsey Judson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-24 00:00:00.000000000 Z
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: dry-struct
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: http
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
110
  version: '4.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: lucid_utils
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.0'
97
125
  description:
98
126
  email: kelsey@lucid.nz
99
127
  executables: []
@@ -119,6 +147,7 @@ files:
119
147
  - lib/lucid_intercom/send_email.rb
120
148
  - lib/lucid_intercom/send_message.rb
121
149
  - lib/lucid_intercom/snippet.html
150
+ - lib/lucid_intercom/types.rb
122
151
  - lib/lucid_intercom/update_user.rb
123
152
  - lib/lucid_intercom/user_attributes.rb
124
153
  - lib/lucid_intercom/version.rb