alexa_couchpotato 1.1.0 → 1.2.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
  SHA1:
3
- metadata.gz: 329c465b1de9775844b6ce0e2977ca0a49e8c430
4
- data.tar.gz: 3413379420a981eebe178293602fb763873df4ef
3
+ metadata.gz: 358053305ed6ded66ba962ecb2b15283200e462d
4
+ data.tar.gz: ef8a0bb1e58957fb1d0bb703d401999b1ca2b176
5
5
  SHA512:
6
- metadata.gz: ed408d76eb1d7b9ff785f3f21bd02efd0f233f4820ecb873dc2a4b0e4c7558778a21fbeb3b81a0020e0cf624f3971bcea2be1a26c2a58d5831bf4b4794c683d3
7
- data.tar.gz: 89e59fcf734cea2cd83346915dbd3a71c3589a8b6a92b3c95ef63e53bd8a1b3421a3c910aae0086f6de15adb0e4de5f37389b934232a4368c6090851728bc028
6
+ metadata.gz: ec6273f02e6c5820b25ffa238e9681c238c8e9442dbdd8087275daea6999f8d236ad21e42d5934891ba68dc46d51804c2e729097f8bffc545ef18b24220b67cb
7
+ data.tar.gz: 1be50a16fa0587dee096976ada4c0dcebf8460543e073a29eef05626776ce367a2bfe25644b7ab8db99c3dfdc260d55955416540be4b342de726b0bbaa0ac632
@@ -5,7 +5,7 @@ require 'alexa_couchpotato/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "alexa_couchpotato"
8
- spec.version = Sinatra::Couchpotato::VERSION
8
+ spec.version = Couchpotato::VERSION
9
9
  spec.authors = ["Kyle Lucas"]
10
10
  spec.email = ["kglucas93@gmail.com"]
11
11
  spec.summary = %q{A sinatra middleware for alexa couhpotato actions.}
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_runtime_dependency 'numbers_in_words'
26
26
  spec.add_runtime_dependency 'activesupport'
27
27
  spec.add_runtime_dependency 'chronic'
28
- spec.add_runtime_dependency 'sinatra'
28
+ spec.add_runtime_dependency 'sinatra-contrib'
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.6"
31
31
  spec.add_development_dependency "rake"
@@ -7,103 +7,84 @@ require 'active_support'
7
7
  require 'active_support/core_ext'
8
8
  require 'chronic'
9
9
  require 'alexa_couchpotato/version'
10
- require 'sinatra/base'
10
+ require 'sinatra/extension'
11
11
 
12
- module Sinatra
13
- module Couchpotato
14
- def self.registered(app)
15
- app.post '/alexa_cp' do
16
- content_type :json
17
- search_endpoint = "http://#{settings.config.couchpotato.url}/movies/api/#{settings.config.couchpotato.api_key}/search"
18
- add_endpoint = "http://#{settings.config.couchpotato.url}/movies/api/#{settings.config.couchpotato.api_key}/movie.add"
12
+ module Couchpotato
13
+ extend Sinatra::Extension
19
14
 
20
- #halt 400, "" unless settings.config.application_id && @application_id == settings.config.application_id
21
-
22
- if @echo_request.launch_request?
23
- response = AlexaObjects::Response.new
24
- response.spoken_response = "I'm ready to download you movies."
25
- response.end_session = false
26
- response.without_card.to_json
27
- puts @echo_request.slots
28
- elsif @echo_request.intent_name == "ControlCouchpotato"
29
- count = 1
30
- begin
31
- case count
32
- when 1
33
- title = @echo_request.slots["movie"]
34
- when 2
35
- word_arr = @echo_request.slots["movie"].split(' ')
36
- nums = word_arr.map {|x|x.in_numbers}
37
- title = ""
38
- word_arr.each_with_index do |x, index|
39
- title << (nums[index] != 0 ? "#{nums[index]}" : x)
40
- title << " " unless index == word_arr.length-1
41
- end
42
- end
43
- query = HTTParty.get(URI.escape("#{search_endpoint}?q=#{title}"))
44
- if query["movies"] && query["movies"].count == 1
45
- movie = query["movies"].first
46
- elsif query["movies"] && query["movies"].count > 1
47
- movie = query["movies"]
48
- end
49
- movie = false if count == 5 && movie.nil?
50
- count += 1
51
- end until movie != nil
52
- response = AlexaObjects::Response.new
53
-
54
- if [movie].flatten(1).count == 1 && movie != false
55
- add_query = HTTParty.get(URI.escape("#{add_endpoint}?title=#{movie["titles"].first}&identifier#{movie["imdb"]}"))
56
- if add_query["success"] = true
57
- response.end_session = true
58
- response.spoken_response = "okay, downloading #{movie["titles"].first}"
59
- elsif movie && add_query["success"] = false
60
- response.end_session = true
61
- response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because it wouldn't add to the server"
62
- end
63
- elsif movie != false && [movie].flatten(1).count > 1
64
- @@movies = movie
65
- response.end_session = false
66
- response.reprompt_text = "Which movie would you like me to download? #{movie.map {|m| m["titles"].first }.to_sentence(:last_word_connector => ' or ')}"
67
- elsif movie == false
68
- response.end_session = true
69
- response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because the search came up empty"
70
- else
71
- response.end_session = true
72
- response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because the search came up empty"
15
+ helpers do
16
+ def control_couchpotato
17
+ count = 1
18
+ begin
19
+ case count
20
+ when 1
21
+ title = @echo_request.slots["movie"]
22
+ when 2
23
+ word_arr = @echo_request.slots["movie"].split(' ')
24
+ nums = word_arr.map {|x|x.in_numbers}
25
+ title = ""
26
+ word_arr.each_with_index do |x, index|
27
+ title << (nums[index] != 0 ? "#{nums[index]}" : x)
28
+ title << " " unless index == word_arr.length-1
73
29
  end
30
+ end
31
+
32
+ query = HTTParty.get(URI.escape("#{search_endpoint}?q=#{title}"))
33
+
34
+ if query["movies"] && query["movies"].count == 1
35
+ movie = query["movies"].first
36
+ elsif query["movies"] && query["movies"].count > 1
37
+ movie = query["movies"]
38
+ end
39
+
40
+ movie = false if count == 5 && movie.nil?
41
+ count += 1
42
+ end until movie != nil
74
43
 
75
- response.without_card.to_json
76
- elsif @echo_request.intent_name == "RespondCouchpotato"
77
- ordinal = Chronic::Numerizer.numerize(@echo_request.slots["listvalue"]).split(' ').last
78
- number = ordinal[0]
79
- movie = @@movies[number.to_i+1]
80
- query = HTTParty.get(URI.escape("#{add_endpoint}?title=#{movie["titles"].first}&identifier#{movie["imdb"]}"))
81
- response = AlexaObjects::Response.new
82
- if movie != false && query["success"] = true
83
- response.end_session = true
84
- response.spoken_response = "okay, downloading #{movie["titles"].first}"
85
- elsif movie == false
86
- response.end_session = true
87
- response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because the search came up empty"
88
- elsif movie && query["success"] = false
89
- response.end_session = true
90
- response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because it wouldn't add to the server"
91
- end
92
- response.without_card.to_json
93
- elsif @echo_request.intent_name == "EndSession"
94
- puts @echo_request.slots
95
- response = AlexaObjects::Response.new
96
- response.end_session = true
97
- response.spoken_response = "exiting couchpoato"
98
- response.without_card.to_json
99
- elsif @echo_request.session_ended_request?
100
- response = AlexaObjects::Response.new
101
- response.end_session = true
102
- response.without_card.to_json
44
+ response = AlexaObjects::Response.new
45
+
46
+ if [movie].flatten(1).count == 1 && movie != false
47
+ add_query = HTTParty.get(URI.escape("#{add_endpoint}?title=#{movie["titles"].first}&identifier#{movie["imdb"]}"))
48
+ if add_query["success"] = true
49
+ response.spoken_response = "okay, downloading #{movie["titles"].first}"
50
+ elsif movie && add_query["success"] = false
51
+ response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because it wouldn't add to the server"
103
52
  end
53
+ elsif movie != false && [movie].flatten(1).count > 1
54
+ @@movies = movie
55
+ response.end_session = false
56
+ response.reprompt_text = "Which movie would you like me to download? #{movie.map {|m| m["titles"].first }.to_sentence(:last_word_connector => ' or ')}"
57
+ elsif movie == false
58
+ response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because the search came up empty"
59
+ else
60
+ response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because the search came up empty"
104
61
  end
62
+
63
+ response.to_json
105
64
  end
106
- end
107
65
 
108
- register Couchpotato
109
- end
66
+ def respond_couchpotato
67
+ ordinal = Chronic::Numerizer.numerize(@echo_request.slots["listvalue"]).split(' ').last
68
+ number = ordinal[0]
69
+ movie = @@movies[number.to_i+1]
70
+ query = HTTParty.get(URI.escape("#{add_endpoint}?title=#{movie["titles"].first}&identifier#{movie["imdb"]}"))
71
+ response = AlexaObjects::Response.new
72
+ if movie != false && query["success"] = true
73
+ response.spoken_response = "okay, downloading #{movie["titles"].first}"
74
+ elsif movie == false
75
+ response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because the search came up empty"
76
+ elsif movie && query["success"] = false
77
+ response.spoken_response = "sorry, I wasn't able to find #{@echo_request.slots["movie"]} because it wouldn't add to the server"
78
+ end
79
+ response.to_json
80
+ end
81
+
82
+ def add_endpoint
83
+ "http://#{settings.config.couchpotato.url}/movies/api/#{settings.config.couchpotato.api_key}/movie.add"
84
+ end
85
+
86
+ def search_endpoint
87
+ "http://#{settings.config.couchpotato.url}/movies/api/#{settings.config.couchpotato.api_key}/search"
88
+ end
89
+ end
90
+ end
@@ -1,7 +1,5 @@
1
- module Sinatra
2
- module Couchpotato
3
- def self.custom_slots
4
- File.read(File.expand_path('../../../skills_config/custom_slots.txt', __FILE__))
5
- end
1
+ module Couchpotato
2
+ def self.custom_slots
3
+ File.read(File.expand_path('../../../skills_config/custom_slots.txt', __FILE__))
6
4
  end
7
- end
5
+ end
@@ -1,7 +1,5 @@
1
- module Sinatra
2
- module Couchpotato
3
- def self.intent_schema
4
- File.read(File.expand_path('../../../skills_config/intent_schema.txt', __FILE__))
5
- end
1
+ module Couchpotato
2
+ def self.intent_schema
3
+ File.read(File.expand_path('../../../skills_config/intent_schema.txt', __FILE__))
6
4
  end
7
- end
5
+ end
@@ -1,7 +1,5 @@
1
- module Sinatra
2
- module Couchpotato
3
- def self.sample_utterances
4
- File.read(File.expand_path('../../../skills_config/sample_utterances.txt', __FILE__))
5
- end
1
+ module Couchpotato
2
+ def self.sample_utterances
3
+ File.read(File.expand_path('../../../skills_config/sample_utterances.txt', __FILE__))
6
4
  end
7
- end
5
+ end
@@ -1,5 +1,4 @@
1
- module Sinatra
2
- module Couchpotato
3
- VERSION = "1.1.0"
4
- end
1
+ module Couchpotato
2
+ VERSION = "1.2.0"
5
3
  end
4
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa_couchpotato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Lucas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-14 00:00:00.000000000 Z
11
+ date: 2016-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: sinatra
98
+ name: sinatra-contrib
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -193,7 +193,6 @@ files:
193
193
  - alexa_couchpotato.gemspec
194
194
  - lib/alexa_couchpotato.rb
195
195
  - lib/alexa_couchpotato/custom_slots.rb
196
- - lib/alexa_couchpotato/endpoint.rb
197
196
  - lib/alexa_couchpotato/intent_schema.rb
198
197
  - lib/alexa_couchpotato/sample_utterances.rb
199
198
  - lib/alexa_couchpotato/version.rb
@@ -1,7 +0,0 @@
1
- module Sinatra
2
- module Couchpotato
3
- def self.endpoint
4
- '/alexa_cp'
5
- end
6
- end
7
- end