alexa-rails 0.1.7 → 2.0.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: 6f7424bec9291cbc50679c312fd312806dd0bfa4e8305204f57a6ddf6b62de2e
4
- data.tar.gz: 4b503fd5f01d4b15ff12e8fef2054fd251f1005a9a32516c1e8eac00fb4dad33
3
+ metadata.gz: 679d2d2731372782d8475c8fc1fd1e34649270aa88a6c5ff47a3a4f9ed2bff11
4
+ data.tar.gz: 3b2f0968c98fc26e92ce8ece3b519c97115eb562e02903ccfbc56d5e19676df4
5
5
  SHA512:
6
- metadata.gz: 7d797df382fb66afc6def0947558e74219c87955c022a0151d7e0044fe1b1605ac23db0b9312eca60fd82d4fb038d01355c48ee152d89de7db97a4b7ae6f54e9
7
- data.tar.gz: 5d4ba2496b7054b58a4925e40ee4815b5d75c40438574e8c9dd939bf693b03d909eec63779f18d6c6751201062aca89a5e60f94eb9bea9efe845135e0318aea2
6
+ metadata.gz: c980eca419ad58dafaad43473f953868c49b10d7692fdb81a14c79a978111be27c0ada1123b6c17c401a70788f2083d402b5082e88f2873f22a6520283579be0
7
+ data.tar.gz: ba6c9e3c01f4be64c4e7891c80457684ad33ad6da2ad515e7cb11815159641e8e10dc0bbb8fe004c428c733d097e7c4b4c886f28651175f9c5fc26d38ccdf52b
data/README.md CHANGED
@@ -22,18 +22,21 @@ $ rake db:migrate
22
22
 
23
23
  ### Configuration
24
24
 
25
- Set alexa skill IDs in environment config (ex: config/environments/development.rb).
26
-
25
+ Add `config/initializers/alexa.rb` and add the following configuration
27
26
 
28
27
  ```ruby
29
- # config/environments/development.rb
28
+ Alexa.configure do |config|
29
+ # Location permissions type
30
+ config.location_permission_type = :country_and_postal_code # or full_address
30
31
 
31
- # For request validation
32
- config.x.alexa.skill_ids = [
33
- "amzn1.ask.skill.xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
34
- ]
32
+ # Default title used on the display cards for your skill
33
+ config.default_card_title = "My Alexa skill"
35
34
 
36
- config.x.alexa.default_card_title = "Alexa rails"
35
+ # Add ID of your skills. Used for request verification
36
+ config.skill_ids = [
37
+ "amzn1.ask.skill.xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"
38
+ ]
39
+ end
37
40
  ```
38
41
 
39
42
  Mount the engine for routes handling in your routes
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "type": "Simple",
3
- "title": "<%= (content_for(:card_title) || Rails.configuration.x.alexa.default_card_title || "Card Title").strip %>",
3
+ "title": "<%= (content_for(:card_title) || Alexa.configuration.default_card_title).strip %>",
4
4
  "content": <%= raw content.strip.to_json %>
5
5
  }
@@ -3,5 +3,9 @@
3
3
  <% end %>
4
4
 
5
5
  <% content_for :permissions_scope do %>
6
- read::alexa:device:all:address
6
+ <% if Alexa.configuration.location_permission_type == :country_and_postal_code %>
7
+ read::alexa:device:all:address:country_and_postal_code
8
+ <% else %>
9
+ read::alexa:device:all:address
10
+ <% end %>
7
11
  <% end %>
@@ -6,6 +6,7 @@ require 'alexa/response'
6
6
  require 'alexa/session'
7
7
  require 'alexa/slot'
8
8
  require 'alexa/version'
9
+ require 'alexa/configuration'
9
10
  require 'alexa/responses/bye'
10
11
  require 'alexa/responses/delegate'
11
12
  require 'alexa/responses/permission_consents/device_address'
@@ -13,7 +14,18 @@ require 'alexa/intent_handlers/base'
13
14
  require_relative '../app/models/alexa/user'
14
15
  require_relative '../app/models/alexa/usage'
15
16
 
16
-
17
17
  module Alexa
18
- # Your code goes here...
18
+ # Manage configuration following the pattern from:
19
+ # https://brandonhilkert.com/blog/ruby-gem-configuration-patterns/
20
+ class << self
21
+ attr_writer :configuration
22
+ end
23
+
24
+ def self.configuration
25
+ @_configuration ||= Alexa::Configuration.new
26
+ end
27
+
28
+ def self.configure
29
+ yield(configuration)
30
+ end
19
31
  end
@@ -0,0 +1,11 @@
1
+ module Alexa
2
+ class Configuration
3
+ attr_accessor :location_permission_type, :default_card_title, :skill_ids
4
+
5
+ def initialize
6
+ @location_permission_type = nil
7
+ @default_card_title = 'Card title'
8
+ @skill_ids = []
9
+ end
10
+ end
11
+ end
@@ -28,33 +28,29 @@ module Alexa
28
28
  # Makes an API to amazon alexa's device location service and returns the
29
29
  # location hash
30
30
  def location
31
- @_location ||= get_location
31
+ @_location ||= begin
32
+ if Alexa.configuration.location_permission_type == :full_address
33
+ get_address
34
+ elsif Alexa.configuration.location_permission_type == :country_and_postal_code
35
+ get_address(only: :country_and_postal_code)
36
+ end
37
+ end
32
38
  end
33
39
 
34
40
  private
35
41
 
36
- def get_location
42
+ def get_address(only: nil)
37
43
  url = "#{@context.api_endpoint}/v1/devices/#{id}/settings/address"
44
+ url = url + "/countryAndPostalCode" if only == :country_and_postal_code
38
45
  conn = Faraday.new(url: url) do |conn|
39
- conn.options["open_timeout"] = 2
40
- conn.options["timeout"] = 3
46
+ conn.options["open_timeout"] = 20
47
+ conn.options["timeout"] = 10
41
48
  conn.adapter :net_http
42
49
  conn.headers["Authorization"] = "Bearer #{@context.api_access_token}"
43
50
  end
44
- begin
45
- resp = conn.get
46
- if resp.status == 200
47
- return JSON.parse(resp.body)
48
- end
49
- rescue Faraday::ConnectionFailed, JSON::ParserError => e
50
- Raven.capture_exception(
51
- e,
52
- extra: {
53
- deviceId: id,
54
- apiEndPoint: @context.api_endpoint
55
- }
56
- )
57
- return {}
51
+ resp = conn.get
52
+ if resp.status == 200
53
+ return JSON.parse(resp.body)
58
54
  end
59
55
  end
60
56
  end
@@ -73,7 +73,7 @@ module Alexa
73
73
  end
74
74
 
75
75
  def valid?
76
- Rails.configuration.x.alexa.skill_ids.include?(application_id)
76
+ Alexa.configuration.skill_ids.include?(application_id)
77
77
  end
78
78
 
79
79
  def intent_name
@@ -1,3 +1,3 @@
1
1
  module Alexa
2
- VERSION = '0.1.7'
2
+ VERSION = '2.0.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sri Vishnu Totakura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-10 00:00:00.000000000 Z
11
+ date: 2018-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,6 +72,7 @@ files:
72
72
  - app/views/layouts/alexa/application.html.erb
73
73
  - config/routes.rb
74
74
  - lib/alexa-rails.rb
75
+ - lib/alexa/configuration.rb
75
76
  - lib/alexa/context.rb
76
77
  - lib/alexa/device.rb
77
78
  - lib/alexa/engine.rb