lily 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 937f85cec9bdc6604cc096fcef5d61c7557b0bb1
4
+ data.tar.gz: 31439a9add04e9b4707feabc6819d95c64551e35
5
+ SHA512:
6
+ metadata.gz: 5b3bc608959bd0aee37a0d2bfeeecf69a675f2a5a1657db7de453ec560e4b0321fd09b538505e67afb371a2a25b9c95cb70f6be60fd88f994187866419156246
7
+ data.tar.gz: 67fcc1bdcd5ace02033181f855b64cb94faf8f7b56e51cc3dde0b186e012f1563fab6638cfc2cf2d30f937dd67818f05daff3e30d0184b16086111d49e3c667b
@@ -0,0 +1,40 @@
1
+ ############
2
+ # Ruby #
3
+ ############
4
+
5
+ *.gem
6
+ *.rbc
7
+ /.config
8
+ /coverage/
9
+ /InstalledFiles
10
+ /pkg/
11
+ /spec/reports/
12
+ /spec/examples.txt
13
+ /test/tmp/
14
+ /test/version_tmp/
15
+ /tmp/
16
+
17
+ ## Specific to RubyMotion:
18
+ .dat*
19
+ .repl_history
20
+ build/
21
+
22
+ ## Documentation cache and generated files:
23
+ /.yardoc/
24
+ /_yardoc/
25
+ /doc/
26
+ /rdoc/
27
+
28
+ ## Environment normalization:
29
+ /.bundle/
30
+ /vendor/bundle
31
+ /lib/bundler/man/
32
+
33
+ # for a library or gem, you might want to ignore these files since the code is
34
+ # intended to run in multiple environments; otherwise, check them in:
35
+ Gemfile.lock
36
+ # .ruby-version
37
+ # .ruby-gemset
38
+
39
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
40
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+ gem 'http'
3
+ gem 'launchy'
data/LICENCE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (c) 2016 Josh Trommel
2
+
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ lily
2
+ ====
3
+
4
+ A simple Last.fm client.
5
+
6
+ ## Development
7
+
8
+ Clone the repo, install the gem, run the binary. It's that simple.
9
+
10
+ ```bash
11
+ git clone https://github.com/trmml/lily
12
+
13
+ cd lily
14
+ gem build lily.gemspec
15
+ gem install lily-*gem # Install the gem
16
+
17
+ lily init # Initialize :)
18
+ ```
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
3
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
4
+
5
+ require 'lily'
6
+ lily = Lily.new(*ARGV.map(&:downcase))
7
+ lily.run
@@ -0,0 +1,116 @@
1
+ require 'json'
2
+ require 'http'
3
+ require 'launchy'
4
+ require 'digest/md5'
5
+ require 'uri'
6
+ require_relative 'lily/version'
7
+ require_relative 'lily/hash'
8
+
9
+ class Lily
10
+ def initialize(*args)
11
+ @args = args
12
+ @file = File.read('lib/lily/keys.json')
13
+ @keys = JSON.parse(@file)
14
+ @lily_json = self.get_lily_json
15
+ @token ||= self.token
16
+ end
17
+
18
+ def get_lily_json
19
+ begin # Make this more concise later
20
+ content = File.read(ENV['HOME'] + '/.lily.json')
21
+ lily_json = JSON.parse(content)
22
+
23
+ # returns {sk, signature}
24
+ rescue
25
+ puts "~/.lily.json appears empty"
26
+ end
27
+ end
28
+
29
+ def format_params(params)
30
+ path_arr = []
31
+ sig_str = ""
32
+ params = params.sort_by { |key, value| key }
33
+ params.each do |key, value|
34
+ path_arr.push("#{key}=" + URI.encode(value.to_s))
35
+ if (key != "format")
36
+ sig_str += key + value.to_s
37
+ end
38
+ end
39
+ sig_str += @keys.private
40
+ sig = Digest::MD5.hexdigest(sig_str)
41
+ path_arr.push("api_sig=#{sig}")
42
+ path = path_arr.join("&")
43
+ return path
44
+ end
45
+
46
+ def token
47
+ url = "http://ws.audioscrobbler.com/2.0/?method=auth.getToken&api_key=#{@keys.public}&api_sig=#{@keys.private}&format=json"
48
+ res = JSON.parse(HTTP.get(url))
49
+ # return res.token
50
+ res.token
51
+ end
52
+
53
+ def auth
54
+ lastfmURL = "http://www.last.fm/api/auth/?api_key=#{@keys.public}&token=#{@token}"
55
+ puts "Press Enter once you've given access."
56
+ Launchy.open(lastfmURL)
57
+ end
58
+
59
+ def session_key
60
+ sig = Digest::MD5.hexdigest("api_key#{@keys.public}methodauth.getSessiontoken#{@token}#{@keys.private}")
61
+ session = "http://ws.audioscrobbler.com/2.0/?method=auth.getSession&api_key=#{@keys.public}&api_sig=#{sig}&token=#{@token}&format=json"
62
+ res = JSON.parse(HTTP.get(session))
63
+ sk = res.session['key']
64
+
65
+ File.open(ENV['HOME'] + '/.lily.json', 'w+') do |file|
66
+ file.write(JSON.pretty_generate({"session_key" => sk}))
67
+ end
68
+ end
69
+
70
+ def scrobble
71
+ # http://www.last.fm/api/show/track.scrobble
72
+ track, artist = @args[0], @args[1]
73
+
74
+ url = "http://ws.audioscrobbler.com/2.0/"
75
+ timestamp = Time.now.utc.to_i # UTC time since unix epoch in seconds
76
+
77
+ body = self.format_params({
78
+ "artist" => artist,
79
+ "method" => "track.scrobble",
80
+ "sk" => @lily_json.session_key,
81
+ "timestamp" => timestamp,
82
+ "track" => track,
83
+ "api_key" => @keys.public,
84
+ "format" => "json"
85
+ })
86
+
87
+ res = HTTP.post(url, :body => body)
88
+
89
+ puts "#{track} by #{artist} has been scrobbled"
90
+ end
91
+
92
+ def run
93
+ first = @args.shift
94
+
95
+ case first
96
+ when 'scrobble' then self.scrobble
97
+ when 'init' then self.init
98
+ else self.help
99
+ end
100
+ end
101
+
102
+ def help
103
+ puts "no"
104
+ end
105
+
106
+ def init
107
+ auth
108
+ STDIN.gets # wow, hack
109
+ session_key
110
+ puts "Initialized successfully"
111
+ end
112
+
113
+ def version
114
+ Version::STRING
115
+ end
116
+ end
@@ -0,0 +1,12 @@
1
+ # I love dot notation more than life itself
2
+ class Hash
3
+ def method_missing(method, *opts)
4
+ m = method.to_s
5
+ if self.has_key?(m)
6
+ return self[m]
7
+ elsif self.has_key?(m.to_sym)
8
+ return self[m.to_sym]
9
+ end
10
+ super
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "public": "238b1080c5a14212261f2c963baaf2db",
3
+ "private": "85fbaa6644c31d879c3e004fbddb82bf"
4
+ }
@@ -0,0 +1,4 @@
1
+ module Version
2
+ LITERAL = '0.1.0'
3
+ STRING = "lily v#{LITERAL}"
4
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/lily/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ['Josh Trommel']
6
+ gem.email = ['joshtrommel@gmail.com']
7
+ gem.description = 'A simple Last.fm client'
8
+ gem.summary = 'Last.fm\'s website is trash, and having a client for it is nice.'
9
+ gem.homepage = 'https://github.com/trmml/lily'
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = ['lily']
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'lily'
15
+ gem.require_paths = ['lib']
16
+ gem.version = Version::LITERAL
17
+ gem.licenses = ['MIT']
18
+
19
+ gem.add_development_dependency "bundler", "~> 1.6"
20
+ gem.add_development_dependency "rake", '~> 0'
21
+
22
+ gem.add_dependency 'http', '~> 1.0', '>= 1.0.2'
23
+ gem.add_dependency 'launchy', '~> 2.4'
24
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lily
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Josh Trommel
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: http
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.2
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.0'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.2
61
+ - !ruby/object:Gem::Dependency
62
+ name: launchy
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.4'
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.4'
75
+ description: A simple Last.fm client
76
+ email:
77
+ - joshtrommel@gmail.com
78
+ executables:
79
+ - lily
80
+ extensions: []
81
+ extra_rdoc_files: []
82
+ files:
83
+ - ".gitignore"
84
+ - Gemfile
85
+ - LICENCE
86
+ - README.md
87
+ - bin/lily
88
+ - lib/lily.rb
89
+ - lib/lily/hash.rb
90
+ - lib/lily/keys.json
91
+ - lib/lily/version.rb
92
+ - lily.gemspec
93
+ homepage: https://github.com/trmml/lily
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Last.fm's website is trash, and having a client for it is nice.
117
+ test_files: []