miles 0.0.2 → 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -3,6 +3,8 @@ libmiles-ruby
3
3
 
4
4
  Ruby implimentation of the Miles Platform API
5
5
 
6
+ [![Build Status](https://travis-ci.org/MilesPlatform/libmiles-ruby.png)](https://travis-ci.org/MilesPlatform/libmiles-ruby)
7
+
6
8
  Installation
7
9
  ------------
8
10
 
data/lib/miles.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'miles/endpoint'
2
2
  require 'miles/tts'
3
3
  require 'miles/stt'
4
- require 'miles/scheduler'
4
+ require 'miles/scheduler'
5
+ require 'miles/audio'
@@ -0,0 +1,45 @@
1
+ require 'httparty'
2
+ require 'json'
3
+
4
+ module Miles
5
+ class Audio
6
+ include HTTParty
7
+
8
+ attr_reader :host, :port, :base_uri
9
+
10
+ def initialize(host, port=80)
11
+ @host = host
12
+ @port = port
13
+ @base_uri = "#{host}#{port != 80 ? ':' + @port.to_s : ''}"
14
+ self.class.base_uri @base_uri
15
+ end
16
+
17
+ def say(text)
18
+ req = {'text' => text}
19
+ response = self.class.post('/say', :body => req.to_json)
20
+ return JSON.parse(response)
21
+ end
22
+
23
+ def search_spotify(query)
24
+ query['service'] = 'spotify'
25
+ response = self.class.post('/search', :body => query.to_json)
26
+ return JSON.parse(response)
27
+ end
28
+
29
+ def play_spotify(track_link=nil)
30
+ query = {'action' => 'play'}
31
+ if not track_link.nil?
32
+ query['link'] = track_link
33
+ end
34
+
35
+ response = self.class.post('/spotify', :body => query.to_json)
36
+ return JSON.parse(response)
37
+ end
38
+
39
+ def pause_spotify
40
+ query = {'action' => 'pause'}
41
+ response = self.class.post('/spotify', :body => query.to_json)
42
+ return JSON.parse(response)
43
+ end
44
+ end
45
+ end
data/lib/miles/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Miles
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1"
3
3
  end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe Miles::Audio do
4
+
5
+ before(:all) do
6
+ @audio = Miles::Audio.new('127.0.0.1', 4567)
7
+ end
8
+
9
+ it 'should instantiate' do
10
+ audio = Miles::Audio.new('127.0.0.1', 4567)
11
+
12
+ audio.should_not be_nil
13
+ audio.host.should == '127.0.0.1'
14
+ audio.port.should == 4567
15
+ audio.base_uri.should == "127.0.0.1:4567"
16
+ end
17
+
18
+ it 'should instruct audio service to synthesize speech' do
19
+ VCR.use_cassette('audio_say') do
20
+ response = @audio.say("This is a test of the Miles Text to Speech service. It's a pleasure to meet you.")
21
+
22
+ response.should be_a_kind_of(Hash)
23
+ response.should have_key("success")
24
+ response['success'].should eq(true)
25
+ end
26
+ end
27
+
28
+ it 'should search spotify for a track by only title' do
29
+ VCR.use_cassette('audio_search_spotify_title') do
30
+ query = {'title' => 'Thrift Shop'}
31
+ response = @audio.search_spotify(query)
32
+
33
+ response.should be_a_kind_of(Hash)
34
+
35
+ response.should have_key('results')
36
+ response['results'].should be_a_kind_of(Array)
37
+ response['results'].length.should eq(10)
38
+
39
+ response['results'].first.should be_a_kind_of(Hash)
40
+ response['results'].first.should have_key('title')
41
+ response['results'].first.should have_key('artist')
42
+ response['results'].first.should have_key('link')
43
+
44
+ response['results'].each do |result|
45
+ result['title'].downcase.include?('thrift shop').should eq(true)
46
+ end
47
+ end
48
+ end
49
+
50
+ it 'should search spotify for a track by only artist' do
51
+ VCR.use_cassette('audio_search_spotify_artist') do
52
+ query = {'artist' => 'Macklemore'}
53
+ response = @audio.search_spotify(query)
54
+
55
+ response.should be_a_kind_of(Hash)
56
+
57
+ response.should have_key('results')
58
+ response['results'].should be_a_kind_of(Array)
59
+ response['results'].length.should eq(10)
60
+
61
+ response['results'].first.should have_key('title')
62
+ response['results'].first.should have_key('artist')
63
+ response['results'].first.should have_key('link')
64
+
65
+ response['results'].each do |result|
66
+ result['artist'].downcase.include?('macklemore').should eq(true)
67
+ end
68
+ end
69
+ end
70
+
71
+ it 'should search spotify for a track by title and artist' do
72
+ VCR.use_cassette('audio_search_spotify_title_artist') do
73
+ query = {'title' => 'Thrift Shop', 'artist' => 'Macklemore'}
74
+ response = @audio.search_spotify(query)
75
+
76
+ response.should be_a_kind_of(Hash)
77
+
78
+ response.should have_key('results')
79
+ response['results'].should be_a_kind_of(Array)
80
+ response['results'].length.should eq(3)
81
+
82
+ response['results'].first.should have_key('title')
83
+ response['results'].first.should have_key('artist')
84
+ response['results'].first.should have_key('link')
85
+
86
+ response['results'].each do |result|
87
+ result['title'].downcase.include?('thrift shop').should eq(true)
88
+ result['artist'].downcase.include?('macklemore').should eq(true)
89
+ end
90
+ end
91
+ end
92
+
93
+ it 'should play a track on spotify' do
94
+ VCR.use_cassette('audio_play_spotify_track') do
95
+ response = @audio.play_spotify('spotify:track:1CmUZGtH29Kx36C1Hleqlz')
96
+
97
+ response.should be_a_kind_of(Hash)
98
+ response.should have_key('success')
99
+ response['success'].should eq(true)
100
+ end
101
+ end
102
+
103
+ it 'should pause the currently playing spotify track' do
104
+ VCR.use_cassette('audio_pause_spotify') do
105
+ response = @audio.pause_spotify
106
+
107
+ response.should be_a_kind_of(Hash)
108
+ response.should have_key('success')
109
+ response['success'].should eq(true)
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:4567/spotify
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"action":"pause"}'
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: ! 'OK '
14
+ headers:
15
+ X-Frame-Options:
16
+ - SAMEORIGIN
17
+ X-Xss-Protection:
18
+ - 1; mode=block
19
+ X-Content-Type-Options:
20
+ - nosniff
21
+ Content-Type:
22
+ - text/html;charset=utf-8
23
+ Content-Length:
24
+ - '16'
25
+ Server:
26
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
27
+ Date:
28
+ - Sun, 03 Mar 2013 23:09:10 GMT
29
+ Connection:
30
+ - Keep-Alive
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"success":true}'
34
+ http_version:
35
+ recorded_at: Sun, 03 Mar 2013 23:09:10 GMT
36
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,36 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:4567/spotify
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"action":"play","link":"spotify:track:1CmUZGtH29Kx36C1Hleqlz"}'
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: ! 'OK '
14
+ headers:
15
+ X-Frame-Options:
16
+ - SAMEORIGIN
17
+ X-Xss-Protection:
18
+ - 1; mode=block
19
+ X-Content-Type-Options:
20
+ - nosniff
21
+ Content-Type:
22
+ - text/html;charset=utf-8
23
+ Content-Length:
24
+ - '16'
25
+ Server:
26
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
27
+ Date:
28
+ - Sun, 03 Mar 2013 23:06:47 GMT
29
+ Connection:
30
+ - Keep-Alive
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"success":true}'
34
+ http_version:
35
+ recorded_at: Sun, 03 Mar 2013 23:06:47 GMT
36
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:4567/say
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"text":"This is a test of the Miles Text to Speech service. It''s
9
+ a pleasure to meet you."}'
10
+ headers: {}
11
+ response:
12
+ status:
13
+ code: 200
14
+ message: ! 'OK '
15
+ headers:
16
+ X-Frame-Options:
17
+ - SAMEORIGIN
18
+ X-Xss-Protection:
19
+ - 1; mode=block
20
+ X-Content-Type-Options:
21
+ - nosniff
22
+ Content-Type:
23
+ - text/html;charset=utf-8
24
+ Content-Length:
25
+ - '16'
26
+ Server:
27
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
28
+ Date:
29
+ - Sun, 03 Mar 2013 22:36:58 GMT
30
+ Connection:
31
+ - Keep-Alive
32
+ body:
33
+ encoding: US-ASCII
34
+ string: ! '{"success":true}'
35
+ http_version:
36
+ recorded_at: Sun, 03 Mar 2013 22:36:58 GMT
37
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:4567/search
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"artist":"Macklemore","service":"spotify"}'
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: ! 'OK '
14
+ headers:
15
+ X-Frame-Options:
16
+ - SAMEORIGIN
17
+ X-Xss-Protection:
18
+ - 1; mode=block
19
+ X-Content-Type-Options:
20
+ - nosniff
21
+ Content-Type:
22
+ - text/html;charset=utf-8
23
+ Content-Length:
24
+ - '1199'
25
+ Server:
26
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
27
+ Date:
28
+ - Sun, 03 Mar 2013 23:01:06 GMT
29
+ Connection:
30
+ - Keep-Alive
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"results":[{"title":"Thrift Shop - feat. Wanz","artist":"Macklemore
34
+ & Ryan Lewis","link":"spotify:track:1CmUZGtH29Kx36C1Hleqlz"},{"title":"Can''t
35
+ Hold Us - feat. Ray Dalton","artist":"Macklemore & Ryan Lewis","link":"spotify:track:3bidbhpOYeV4knp8AIu8Xn"},{"title":"Same
36
+ Love - feat. Mary Lambert","artist":"Macklemore & Ryan Lewis","link":"spotify:track:01uqI4H13Gsd8Lyl1EYd8H"},{"title":"And
37
+ We Danced (feat. Ziggy Stardust)","artist":"Macklemore","link":"spotify:track:1FCQEg7wOK9IIBuxx63krr"},{"title":"Otherside
38
+ (feat. Fences) [Ryan Lewis Remix]","artist":"Macklemore & Ryan Lewis","link":"spotify:track:3JIqogHHQIQW1uJ5Yivb88"},{"title":"Thrift
39
+ Shop - feat. Wanz","artist":"Macklemore & Ryan Lewis","link":"spotify:track:37rKwjBHaZurlyPYy3Nqvz"},{"title":"Ten
40
+ Thousand Hours","artist":"Macklemore & Ryan Lewis","link":"spotify:track:0dlxqODS4xOn7pwjKXZZuc"},{"title":"Wings","artist":"Macklemore
41
+ & Ryan Lewis","link":"spotify:track:0rf8whOpWQjuBqQwPbtLma"},{"title":"Thin
42
+ Line - feat. Buffalo Madonna","artist":"Macklemore & Ryan Lewis","link":"spotify:track:7kugTkQLsvtjM7esCEI8Ee"},{"title":"Make
43
+ The Money","artist":"Macklemore & Ryan Lewis","link":"spotify:track:7g3bGUwZaMp0Wve2wSp50F"}]}'
44
+ http_version:
45
+ recorded_at: Sun, 03 Mar 2013 23:01:06 GMT
46
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:4567/search
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"title":"Thrift Shop","service":"spotify"}'
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: ! 'OK '
14
+ headers:
15
+ X-Frame-Options:
16
+ - SAMEORIGIN
17
+ X-Xss-Protection:
18
+ - 1; mode=block
19
+ X-Content-Type-Options:
20
+ - nosniff
21
+ Content-Type:
22
+ - text/html;charset=utf-8
23
+ Content-Length:
24
+ - '1149'
25
+ Server:
26
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
27
+ Date:
28
+ - Sun, 03 Mar 2013 22:50:01 GMT
29
+ Connection:
30
+ - Keep-Alive
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"results":[{"title":"Thrift Shop - feat. Wanz","artist":"Macklemore
34
+ & Ryan Lewis","link":"spotify:track:1CmUZGtH29Kx36C1Hleqlz"},{"title":"Thrift
35
+ Shop - feat. Wanz","artist":"Macklemore & Ryan Lewis","link":"spotify:track:37rKwjBHaZurlyPYy3Nqvz"},{"title":"Thrift
36
+ Shop - feat. Wanz","artist":"Macklemore & Ryan Lewis","link":"spotify:track:4YMqbFcDIFiCBd02PzUBcM"},{"title":"Thrift
37
+ Shop","artist":"Thrift Shop","link":"spotify:track:2BDTE6rrbS68wLfnei7KRA"},{"title":"Thrift
38
+ Shop (originally by Macklemore)","artist":"Tyler Ward & Lindsey Stirling","link":"spotify:track:0EYKD5N0mldDeVTCzCfzqr"},{"title":"Thrift
39
+ Shop","artist":"Thrift Shop","link":"spotify:track:5CqqRZrDdgcIF10wSmHVa8"},{"title":"Thrift
40
+ Shop (originally by Macklemore)","artist":"Alex G","link":"spotify:track:5N790g9r2exNLATjCto9X7"},{"title":"Thrift
41
+ Shop (Super Clean Radio Mix)","artist":"Mama''s Soap Shop","link":"spotify:track:18FLjY5QEm4iaVFLzyYwqb"},{"title":"Thrift
42
+ Shop (Clean Remix)","artist":"Groove Shop","link":"spotify:track:25ntvxjsygfM9NVeKr6jch"},{"title":"Thrift
43
+ Shop (Clean Version)","artist":"New Re-Mix Squad","link":"spotify:track:0myBPkLccu6eGIwAJePjLE"}]}'
44
+ http_version:
45
+ recorded_at: Sun, 03 Mar 2013 22:50:01 GMT
46
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,39 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://127.0.0.1:4567/search
6
+ body:
7
+ encoding: UTF-8
8
+ string: ! '{"title":"Thrift Shop","artist":"Macklemore","service":"spotify"}'
9
+ headers: {}
10
+ response:
11
+ status:
12
+ code: 200
13
+ message: ! 'OK '
14
+ headers:
15
+ X-Frame-Options:
16
+ - SAMEORIGIN
17
+ X-Xss-Protection:
18
+ - 1; mode=block
19
+ X-Content-Type-Options:
20
+ - nosniff
21
+ Content-Type:
22
+ - text/html;charset=utf-8
23
+ Content-Length:
24
+ - '367'
25
+ Server:
26
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-04-20)
27
+ Date:
28
+ - Sun, 03 Mar 2013 23:02:19 GMT
29
+ Connection:
30
+ - Keep-Alive
31
+ body:
32
+ encoding: US-ASCII
33
+ string: ! '{"results":[{"title":"Thrift Shop - feat. Wanz","artist":"Macklemore
34
+ & Ryan Lewis","link":"spotify:track:1CmUZGtH29Kx36C1Hleqlz"},{"title":"Thrift
35
+ Shop - feat. Wanz","artist":"Macklemore & Ryan Lewis","link":"spotify:track:37rKwjBHaZurlyPYy3Nqvz"},{"title":"Thrift
36
+ Shop - feat. Wanz","artist":"Macklemore & Ryan Lewis","link":"spotify:track:4YMqbFcDIFiCBd02PzUBcM"}]}'
37
+ http_version:
38
+ recorded_at: Sun, 03 Mar 2013 23:02:19 GMT
39
+ recorded_with: VCR 2.4.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: miles
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: '0.1'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,13 +25,21 @@ files:
25
25
  - README.md
26
26
  - Rakefile
27
27
  - lib/miles.rb
28
+ - lib/miles/audio.rb
28
29
  - lib/miles/endpoint.rb
29
30
  - lib/miles/scheduler.rb
30
31
  - lib/miles/stt.rb
31
32
  - lib/miles/tts.rb
32
33
  - lib/miles/version.rb
33
34
  - miles.gemspec
35
+ - spec/audio_spec.rb
34
36
  - spec/endpoint_spec.rb
37
+ - spec/fixtures/vcr_cassettes/audio_pause_spotify.yml
38
+ - spec/fixtures/vcr_cassettes/audio_play_spotify_track.yml
39
+ - spec/fixtures/vcr_cassettes/audio_say.yml
40
+ - spec/fixtures/vcr_cassettes/audio_search_spotify_artist.yml
41
+ - spec/fixtures/vcr_cassettes/audio_search_spotify_title.yml
42
+ - spec/fixtures/vcr_cassettes/audio_search_spotify_title_artist.yml
35
43
  - spec/fixtures/vcr_cassettes/endpoint_dewpoint.yml
36
44
  - spec/fixtures/vcr_cassettes/endpoint_get_pin.yml
37
45
  - spec/fixtures/vcr_cassettes/endpoint_humidity.yml
@@ -65,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
73
  version: '0'
66
74
  segments:
67
75
  - 0
68
- hash: 3400744694015592574
76
+ hash: 1467447024361054951
69
77
  required_rubygems_version: !ruby/object:Gem::Requirement
70
78
  none: false
71
79
  requirements:
@@ -79,7 +87,14 @@ signing_key:
79
87
  specification_version: 3
80
88
  summary: ''
81
89
  test_files:
90
+ - spec/audio_spec.rb
82
91
  - spec/endpoint_spec.rb
92
+ - spec/fixtures/vcr_cassettes/audio_pause_spotify.yml
93
+ - spec/fixtures/vcr_cassettes/audio_play_spotify_track.yml
94
+ - spec/fixtures/vcr_cassettes/audio_say.yml
95
+ - spec/fixtures/vcr_cassettes/audio_search_spotify_artist.yml
96
+ - spec/fixtures/vcr_cassettes/audio_search_spotify_title.yml
97
+ - spec/fixtures/vcr_cassettes/audio_search_spotify_title_artist.yml
83
98
  - spec/fixtures/vcr_cassettes/endpoint_dewpoint.yml
84
99
  - spec/fixtures/vcr_cassettes/endpoint_get_pin.yml
85
100
  - spec/fixtures/vcr_cassettes/endpoint_humidity.yml