askio 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/askio.rb +131 -0
  5. metadata +86 -0
  6. metadata.gz.sig +0 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c03dcd3a72ae5c0a7539b2f4c5055611f18436f0
4
+ data.tar.gz: 74bb23a58006de04fbbf285e253fccd6653f4698
5
+ SHA512:
6
+ metadata.gz: 3a32264f1342d85f333eb093864d968f1244449d2b54f13a73a2968ed8eba5897d433eb8ff850186a4cc3a61736c90b14dd506f63bfaf674a888ebc9469f6a35
7
+ data.tar.gz: b96abc047bb5f8920bfb0955e89daf6cb594716301e3175b726bb9ceee1eb88d1ace5f09846a36778cd2c684d82c5651e709f2e446052382aeec9af283224247
Binary file
Binary file
@@ -0,0 +1,131 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: askio.rb
4
+
5
+ require 'time'
6
+ require 'rest-client'
7
+
8
+
9
+
10
+ class AskIO
11
+
12
+ attr_reader :invocation, :utterances
13
+
14
+ def initialize(manifest, model, debug: false, userid: nil,
15
+ deviceid: nil, appid: nil)
16
+
17
+ @debug, @userid, @deviceid, @appid = debug, userid, deviceid, appid
18
+
19
+ @locale = manifest['manifest']['publishingInformation']['locales']\
20
+ .keys.first
21
+ puts '@locale: ' + @locale.inspect if @debug
22
+
23
+ @invocation = model['interactionModel']['languageModel']['invocationName']
24
+
25
+ @utterances = model['interactionModel']['languageModel']\
26
+ ['intents'].inject({}) do |r, intent|
27
+ intent['samples'].each {|x| r[x.downcase] = intent['name']}
28
+ r
29
+ end
30
+
31
+ puts ' debugger::@utterances: ' + @utterances.inspect if @debug
32
+
33
+ @endpoint = manifest['manifest']['apis']['custom']['endpoint']['uri']
34
+
35
+ puts ' debugger: @endpoint: ' + @endpoint.inspect if @debug
36
+
37
+ end
38
+
39
+ def ask(request)
40
+
41
+
42
+ r = @utterances[request]
43
+ puts ' debugger: r: ' + r.inspect if @debug
44
+ puts
45
+
46
+ if r then
47
+
48
+ puts ' debugger: your intent is to ' + r if @debug
49
+
50
+ respond(r)
51
+
52
+ end
53
+
54
+ end
55
+
56
+
57
+ private
58
+
59
+ def post(url, h)
60
+
61
+ r = RestClient.post(url, h.to_json,
62
+ headers={content_type: :json, accept: :json})
63
+ JSON.parse r.body, symbolize_names: true
64
+
65
+ end
66
+
67
+ def respond(intent=nil)
68
+
69
+ h = {"version"=>"1.0",
70
+ "session"=>
71
+ {"new"=>true,
72
+ "sessionId"=>"amzn1.echo-api.session.1",
73
+ "application"=>
74
+ {"applicationId"=>""},
75
+ "user"=>
76
+ {"userId"=>""}},
77
+ "context"=>
78
+ {"System"=>
79
+ {"application"=>
80
+ {"applicationId"=>""},
81
+ "user"=>
82
+ {"userId"=>""},
83
+ "device"=>
84
+ {"deviceId"=>"",
85
+ "supportedInterfaces"=>{}},
86
+ "apiEndpoint"=>"https://api.eu.amazonalexa.com",
87
+ "apiAccessToken"=>
88
+ "A"}},
89
+ "request"=> {}
90
+ }
91
+
92
+ if @userid then
93
+ h['session']['user']['userId'] = @userid
94
+ h['context']['System']['user']['userId'] = @userid
95
+ end
96
+
97
+ h['context']['System']['device']['deviceId'] = @deviceid if @deviceid
98
+
99
+ if @appid then
100
+ h['session']['appliaction']['applicationId'] = @appid
101
+ h['context']['System']['application']['applicationId'] = @appid
102
+ end
103
+
104
+
105
+ h['request'] = if intent then
106
+ {
107
+ "type"=>"IntentRequest",
108
+ "requestId"=>"amzn1.echo-api.request.0",
109
+ "timestamp"=>Time.now.utc.iso8601,
110
+ "locale"=>@locale,
111
+ "intent"=>{"name"=>intent, "confirmationStatus"=>"NONE"},
112
+ "dialogState"=>"STARTED"
113
+ }
114
+ else
115
+ {
116
+ "type"=>"LaunchRequest",
117
+ "requestId"=>"amzn1.echo-api.request.a",
118
+ "timestamp"=> Time.now.utc.iso8601,
119
+ "locale"=>@locale,
120
+ "shouldLinkResultBeReturned"=>false
121
+ }
122
+ end
123
+
124
+ r = post @endpoint, h
125
+ puts ' degbugger: r: ' + r.inspect if @debug
126
+
127
+ r[:response][:outputSpeech][:text]
128
+ end
129
+
130
+ end
131
+
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: askio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
+ YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwNzMwMDg1NTUwWhcN
15
+ MTkwNzMwMDg1NTUwWjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
+ cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDPO8Cl
17
+ iiXDFCt7dkpFiONQ/y7vu24F5ZNNQccqlY7W+2JV6cNeOt6ZKM9ArPGC3DxyHU/R
18
+ mGo+RaddN7648JALNfKFesn7nn2G3IzI83rJmVOjbXeVUriLRDXRZ5PeZjv8swE0
19
+ 7M5aQrQYC0YxDwYQuap+dqVoCkdBHw7hLfkMFz/5nX/0CWjt5vHbFDXVXKvlp0K7
20
+ VwYYykA9HtJFfi8k3JXSbI7OwY75YbdSmvxPu1MVMH4dzffkExk/jmYTlBH6Pf6G
21
+ WEk7zNoGAuGmFJ3kwq7osZ1dJQoIfHkMBuXD/S2py7Y5gdrWe8+9P4m1BNq4lcgS
22
+ wvLs9pCAOaZJwrHTAgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
23
+ HQYDVR0OBBYEFCfe5bRdoD+4F3PXyxBDj6/E9g1LMCYGA1UdEQQfMB2BG2dlbW1h
24
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTAmBgNVHRIEHzAdgRtnZW1tYXN0ZXJAamFt
25
+ ZXNyb2JlcnRzb24uZXUwDQYJKoZIhvcNAQEFBQADggEBAFptZb/AmPB8qYpAAnRr
26
+ ZBkfnV+wWKoOnMOwlArT4BLzirag8jaituLQZYJ/vOLIVTkju7zTZIY5mk7H5PCR
27
+ I6eO+FpfzJ5/LVM+qWtfJ6OUxTo+QblHWKYwQ6In+ldKBGbS/zxzFlwh8hFpJm72
28
+ w7F68u9XnVj0bvq58Y5lYIlUakhCcrl2Me6L4L/fK2/oaXtqfp6MaRMxRklNvxPD
29
+ dyL9A9xqRM7LaZKCnYr1qO9486biqRS1QaQ2Va/qjKpZIVC6iX6XueiBxRu3DEwt
30
+ YfpmspikspKtgVD1CdHOswcx2398iKR/EffL5XcNVPEvOPC+QjnVMvmC8Hu9wtCt
31
+ qJY=
32
+ -----END CERTIFICATE-----
33
+ date: 2018-07-30 00:00:00.000000000 Z
34
+ dependencies:
35
+ - !ruby/object:Gem::Dependency
36
+ name: rest-client
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 2.0.2
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '2.0'
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.2
55
+ description:
56
+ email: james@jamesrobertson.eu
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - lib/askio.rb
62
+ homepage: https://github.com/jrobertson/askio
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.6.13
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Interacts with an HTTP service used to respond to an Amazon Alexa Skill request.
86
+ test_files: []
Binary file