spotifysearch 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 15fd8da9197fda745bfe9f6a45de61b0f56888e0
4
+ data.tar.gz: 31fd926a0eeb6785e8235635559f25ab60f40c66
5
+ SHA512:
6
+ metadata.gz: 43e744924569857776d33531298fcd97028552c91b2c4f2c917386ae4800b20242d6f729744354c43d3388cf83912b01ae396fe0556cc05a6287f600ad1e4883
7
+ data.tar.gz: e3aa999c5abe649f05723b90c742dea4d9ceceeaee3a853eedfd5bfeed6ff2db8816ebf15f6dd86c224649faaca62547402b97a4641397d1aedff6e6932d3fdf
@@ -0,0 +1,6 @@
1
+ config/
2
+ coverage/
3
+ spec/fixtures/
4
+ spec/coverage/
5
+ spec/fixtures/cassettes
6
+ Gemfile.lock
@@ -0,0 +1,7 @@
1
+ ---
2
+ AllCops:
3
+ TargetRubyVersion: 2.3
4
+ Style/FrozenStringLiteralComment:
5
+ Enabled: false
6
+ Style/Tab:
7
+ Enabled: false
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ - 2.2
5
+ - 2.1
6
+ branches:
7
+ only:
8
+ - master
9
+ - travis
10
+ script: bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Lemon555
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,42 @@
1
+ # Spotifysearch Gem
2
+ [![Build Status](https://travis-ci.org/Lemon555/Spotify_Card.svg?branch=master)](https://travis-ci.org/Lemon555/Spotify_Card)
3
+
4
+ Spotifysearch Gem helps you generate your song into a picture to share on social media!
5
+ * Auto search for nice album artwork
6
+ * Change the image you like
7
+ * Add comments on the image and songs to create your own awesome artwork!
8
+ * Share on multiple social network to express your music loving soul!
9
+
10
+ ##Install
11
+
12
+ If you are working on a project, add this to your Gemfile: ```gem 'spotifysearch'```
13
+
14
+ For installation from command line:
15
+
16
+ ```
17
+ $ gem install spotifysearch
18
+ ```
19
+
20
+ ##Usage
21
+
22
+ Require Spotifysearch gem in your code: require 'Spotifysearch'
23
+
24
+ You should use a track name as the input argument.
25
+
26
+ **Notice that you have to use plus sign ("+") instead of a blank to combine each word.
27
+
28
+ For example, If "Eyes Shut" is the track name you want to search, "Eyes+Shut" is the correct type of input.
29
+
30
+ See the following example code for more usage details:
31
+
32
+ ```
33
+ search = Spotify::Search.find(user_input)
34
+ puts 'Search Result:'
35
+ search.each_value do |songinfo|
36
+ puts "track: #{songinfo.track_name}"
37
+ puts "artist: #{songinfo.artist_name}"
38
+ puts "album: #{songinfo.album_name}"
39
+ puts "img_url: #{songinfo.imgs[0]}"
40
+ puts
41
+ end
42
+ ```
@@ -0,0 +1,32 @@
1
+ require 'rake/testtask'
2
+
3
+ task default: :spec
4
+
5
+ desc 'run tests'
6
+ task :spec do
7
+ sh 'ruby spec/card_spec.rb'
8
+ end
9
+
10
+ desc 'delete cassette fixtures'
11
+ task :wipe do
12
+ sh 'rm spec/fixtures/cassettes/*.yml' do |ok, _|
13
+ puts(ok ? 'Cassettes deleted' : 'No casseettes found')
14
+ end
15
+ end
16
+
17
+ namespace :quality do
18
+ desc 'run all quality checks'
19
+ task all: [:rubocop, :flog, :flay]
20
+
21
+ task :flog do
22
+ sh 'flog lib/'
23
+ end
24
+
25
+ task :flay do
26
+ sh 'flay lib/'
27
+ end
28
+
29
+ task :rubocop do
30
+ sh 'rubocop'
31
+ end
32
+ end
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
+ require 'spotifysearch'
5
+
6
+ user_input = ARGV[0]
7
+ unless user_input
8
+ puts 'USAGE: spotifysearch [user_input]'
9
+ exit(1)
10
+ end
11
+
12
+ search = Spotify::Search.find(user_input)
13
+ puts 'Search Result:'
14
+ search.each_value do |songinfo|
15
+ puts "track: #{songinfo.track_name}"
16
+ puts "artist: #{songinfo.artist_name}"
17
+ puts "album: #{songinfo.album_name}"
18
+ puts "img_url: #{songinfo.imgs[0]}"
19
+ puts
20
+ end
@@ -0,0 +1,2 @@
1
+ files = Dir.glob(File.join(File.dirname(__FILE__), 'spotifysearch/*.rb'))
2
+ files.each { |lib| require_relative lib }
@@ -0,0 +1,42 @@
1
+ require 'http'
2
+ require_relative 'song'
3
+ require_relative 'spotify_api'
4
+
5
+ module Spotify
6
+ # Search for a specfic track
7
+ class SongsHash
8
+ attr_accessor :songs_hash
9
+
10
+ # Decompose the search_result and create a "Song" object for each album
11
+ def self.create(search_result)
12
+ @songs_hash = {}
13
+ search_result.map do |song|
14
+ @songs_hash[song['id']] = {
15
+ id: song['id'], track_name: song['name'],
16
+ link: song['external_urls']['spotify'], album: song['album']['name'],
17
+ artist: get_artists(song['artists']),
18
+ imgs: get_album_imgs(song['album']['images'])
19
+ }
20
+ end
21
+ @songs_hash
22
+ end
23
+
24
+ # We don't flay get_artists and get_album_imgs method cause for future uses.
25
+ def self.get_artists(artists)
26
+ # Return an array including all artists of the song
27
+ arr = []
28
+ artists.each do |artist|
29
+ arr.push(artist['name'])
30
+ end
31
+ arr
32
+ end
33
+
34
+ def self.get_album_imgs(images)
35
+ # Return an array including all url of each size of image
36
+ # imgs[0]:L, imgs[1]:M, imgs[2]:S
37
+ imgs = []
38
+ images.each { |img| imgs.push(img['url']) }
39
+ imgs
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require_relative 'spotify_api'
2
+ require_relative 'song'
3
+
4
+ module Spotify
5
+ # Create a Song object
6
+ class Search
7
+ attr_accessor :songs
8
+
9
+ def initialize(search_data)
10
+ @songs = {}
11
+ search_data.each do |key, value|
12
+ @songs[key] = Spotify::Song.new(data: value)
13
+ end
14
+ end
15
+
16
+ def self.find(input)
17
+ search_data = Spotify::SpAPI.search_feed(input)
18
+ new(search_data).songs
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Spotify
2
+ # Create a Song object
3
+ class Song
4
+ attr_accessor :track_name, :track_link, :album_name, :artist_name, :imgs
5
+
6
+ def initialize(data: nil)
7
+ load_data(data)
8
+ end
9
+
10
+ private
11
+
12
+ def load_data(data)
13
+ @track_name = data[:track_name]
14
+ @track_link = data[:link]
15
+ @album_name = data[:album]
16
+ @artist_name = data[:artist]
17
+ @imgs = data[:imgs]
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ require 'http'
2
+ require 'json'
3
+ require_relative 'api_helper'
4
+
5
+ module Spotify
6
+ # Service for all Spotify API calls
7
+ class SpAPI
8
+ SP_URL = 'https://api.spotify.com'.freeze
9
+ API_VER = 'v1'.freeze
10
+ SP_API_URL = URI.join(SP_URL, "#{API_VER}/")
11
+ SEARCH_TYPE = 'track'.freeze
12
+
13
+ def self.search_feed(input)
14
+ search_response = HTTP.get(
15
+ URI.join(SP_API_URL, 'search'),
16
+ params: { q: input, type: SEARCH_TYPE }
17
+ )
18
+ rawfeed = JSON.parse(search_response.to_s)['tracks']['items']
19
+ Spotify::SongsHash.create(rawfeed)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Spotify
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1 @@
1
+ # This is test's README.md
@@ -0,0 +1,43 @@
1
+ require_relative 'spec_helper'
2
+
3
+ describe 'card specifications' do
4
+ VCR.configure do |c|
5
+ c.cassette_library_dir = CASSETTES_FOLDER
6
+ c.hook_into :webmock
7
+ end
8
+
9
+ before do
10
+ VCR.insert_cassette CASSETTE_FILE, record: :new_episodes
11
+ @spotify_api = Spotify::SpAPI.new
12
+ @track_id = '2xzzSkFGtf0w5ZATRYa1Tg'
13
+ end
14
+
15
+ after do
16
+ VCR.eject_cassette
17
+ end
18
+
19
+ it 'should be able to get a hash from SpAPI Class' do
20
+ search = Spotify::Search.find('Eyes Shut')
21
+ search.is_a?(Hash)
22
+ end
23
+
24
+ it 'should be able to get the name of a track' do
25
+ search = Spotify::Search.find('Eyes Shut')
26
+ search[@track_id].track_name = 'Eyes Shut'
27
+ end
28
+
29
+ it 'should be able to get a list of name of artist' do
30
+ search = Spotify::Search.find('Eyes Shut')
31
+ search[@track_id].artist_name = 'Years & Years'
32
+ end
33
+
34
+ it 'should be able to get the name of the album' do
35
+ search = Spotify::Search.find('Eyes Shut')
36
+ search[@track_id].album_name = 'Communion (Deluxe)'
37
+ end
38
+
39
+ it 'should be able to get a array of images' do
40
+ search = Spotify::Search.find('Eyes Shut')
41
+ search[@track_id].imgs.is_a?(Array)
42
+ end
43
+ end
@@ -0,0 +1,17 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
4
+ require 'yaml'
5
+ require 'minitest/autorun'
6
+ require 'minitest/rg'
7
+ require 'vcr'
8
+ require 'webmock'
9
+
10
+ require_relative '../lib/spotifysearch'
11
+
12
+ FIXTURES_FOLDER = 'spec/fixtures'.freeze
13
+ CASSETTES_FOLDER = "#{FIXTURES_FOLDER}/cassettes".freeze
14
+ CASSETTE_FILE = 'spotify_api'.freeze
15
+ # CREDENTIALS = YAML.load(File.read('../config/credentials.yml'))
16
+ # RESULT_FILE = "#{FIXTURES_FOLDER}/results.yml"
17
+ # SPOTIFY_RESULT = YAML.load(File.read(RESULT_FILE))
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
2
+ require 'spotifysearch/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'spotifysearch'
6
+ s.version = Spotify::VERSION
7
+
8
+ s.summary = "Get song's search result from Spotify"
9
+ s.description = 'Extracts name, link, album, artist, imgs from a search'
10
+ s.authors = ['Lemon555']
11
+ s.email = ['wenyun.she@iss.nthu.edu.tw']
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- spec/*`.split("\n")
15
+ s.executables << 'spotifysearch'
16
+
17
+ s.add_runtime_dependency 'http', '~> 2.0'
18
+
19
+ s.add_development_dependency 'minitest', '~> 5.9'
20
+ s.add_development_dependency 'minitest-rg', '~> 5.2'
21
+ s.add_development_dependency 'rake', '~> 10.4'
22
+ s.add_development_dependency 'vcr', '~> 3.0'
23
+ s.add_development_dependency 'webmock', '~> 2.1'
24
+ s.add_development_dependency 'simplecov', '~> 0.12'
25
+ s.add_development_dependency 'flog', '~> 4.4'
26
+ s.add_development_dependency 'flay', '~> 2.8'
27
+ s.add_development_dependency 'rubocop', '~> 0.43'
28
+
29
+ s.homepage = 'https://github.com/Lemon555/Spotify_Card'
30
+ s.license = 'MIT'
31
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spotifysearch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lemon555
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: http
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '5.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '5.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-rg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.12'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.12'
111
+ - !ruby/object:Gem::Dependency
112
+ name: flog
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '4.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '4.4'
125
+ - !ruby/object:Gem::Dependency
126
+ name: flay
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.8'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.8'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.43'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.43'
153
+ description: Extracts name, link, album, artist, imgs from a search
154
+ email:
155
+ - wenyun.she@iss.nthu.edu.tw
156
+ executables:
157
+ - spotifysearch
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".rubocop.yml"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - LICENSE
167
+ - README.md
168
+ - Rakefile
169
+ - bin/spotifysearch
170
+ - lib/spotifysearch.rb
171
+ - lib/spotifysearch/api_helper.rb
172
+ - lib/spotifysearch/search.rb
173
+ - lib/spotifysearch/song.rb
174
+ - lib/spotifysearch/spotify_api.rb
175
+ - lib/spotifysearch/version.rb
176
+ - spec/README.md
177
+ - spec/card_spec.rb
178
+ - spec/spec_helper.rb
179
+ - spotifysearch.gemspec
180
+ homepage: https://github.com/Lemon555/Spotify_Card
181
+ licenses:
182
+ - MIT
183
+ metadata: {}
184
+ post_install_message:
185
+ rdoc_options: []
186
+ require_paths:
187
+ - lib
188
+ required_ruby_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ required_rubygems_version: !ruby/object:Gem::Requirement
194
+ requirements:
195
+ - - ">="
196
+ - !ruby/object:Gem::Version
197
+ version: '0'
198
+ requirements: []
199
+ rubyforge_project:
200
+ rubygems_version: 2.6.6
201
+ signing_key:
202
+ specification_version: 4
203
+ summary: Get song's search result from Spotify
204
+ test_files:
205
+ - spec/README.md
206
+ - spec/card_spec.rb
207
+ - spec/spec_helper.rb