purdie 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 31d6b1e3cbef34b1098dfabf0f1292d0940a2a12
4
+ data.tar.gz: 0fcbedb9b227cfa216b7d19ff5bce6aec4b692c7
5
+ SHA512:
6
+ metadata.gz: 9e779de8221b809cc037ca0d5eadffee0ba98bcd10baee35787d0458a64cbf9c33533b4833dfae05dc9b16e2d4f1b4e15bdc32bb6fc2d7eec53de446502d4316
7
+ data.tar.gz: 7af273293787e5c557ef6ddbaf1d63ed4ddcb9c832484abd504b3182f664bf7af393438b770ddad45c12bcdad6e44ab8ebc8868383cf5de812aa41c22a52aabc
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ .purdie
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format doc
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.1.5
5
+ env:
6
+ global:
7
+ - secure: mVOTPzF5AOokBVUmC8rqGb1ZSQc8RnWfarni5fEBzmdoQ1zz++X3V3WSWfB1YebK5UEGOppngu7dgAn5okkcQI+ohBk9yvWv2WMSWGwE3/ZHq2tKxo2TAvHbfS1vPCLFilzaF3D3csf9l89Z0Kyv+wY78un+ZFcS2UwCjL/7uwk=
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in purdie.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,86 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ guard "cucumber" do
27
+ watch(%r{^features/.+\.feature$})
28
+ watch(%r{^features/support/.+$}) { "features" }
29
+
30
+ watch(%r{^features/step_definitions/(.+)_steps\.rb$}) do |m|
31
+ Dir[File.join("**/#{m[1]}.feature")][0] || "features"
32
+ end
33
+ end
34
+
35
+ # Note: The cmd option is now required due to the increasing number of ways
36
+ # rspec may be run, below are examples of the most common uses.
37
+ # * bundler: 'bundle exec rspec'
38
+ # * bundler binstubs: 'bin/rspec'
39
+ # * spring: 'bin/rspec' (This will use spring if running and you have
40
+ # installed the spring binstubs per the docs)
41
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
42
+ # * 'just' rspec: 'rspec'
43
+
44
+ guard :rspec, cmd: "bundle exec rspec" do
45
+ require "guard/rspec/dsl"
46
+ dsl = Guard::RSpec::Dsl.new(self)
47
+
48
+ # Feel free to open issues for suggestions and improvements
49
+
50
+ # RSpec files
51
+ rspec = dsl.rspec
52
+ watch(rspec.spec_helper) { rspec.spec_dir }
53
+ watch(rspec.spec_support) { rspec.spec_dir }
54
+ watch(rspec.spec_files)
55
+
56
+ # Ruby files
57
+ ruby = dsl.ruby
58
+ dsl.watch_spec_files_for(ruby.lib_files)
59
+
60
+ # Rails files
61
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
62
+ dsl.watch_spec_files_for(rails.app_files)
63
+ dsl.watch_spec_files_for(rails.views)
64
+
65
+ watch(rails.controllers) do |m|
66
+ [
67
+ rspec.spec.("routing/#{m[1]}_routing"),
68
+ rspec.spec.("controllers/#{m[1]}_controller"),
69
+ rspec.spec.("acceptance/#{m[1]}")
70
+ ]
71
+ end
72
+
73
+ # Rails config changes
74
+ watch(rails.spec_helper) { rspec.spec_dir }
75
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
76
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
77
+
78
+ # Capybara features specs
79
+ watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
80
+
81
+ # Turnip features and steps
82
+ watch(%r{^spec/acceptance/(.+)\.feature$})
83
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
84
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
85
+ end
86
+ end
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ ##Copyright (c) 2015 Raw Funk Maharishi
2
+
3
+ #MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,7 @@
1
+ [![Build Status](http://img.shields.io/travis/rawfunkmaharishi/purdie.svg?style=flat-square)](https://travis-ci.org/rawfunkmaharishi/purdie)
2
+ [![Dependency Status](http://img.shields.io/gemnasium/rawfunkmaharishi/purdie.svg?style=flat-square)](https://gemnasium.com/rawfunkmaharishi/purdie)
3
+ [![Coverage Status](http://img.shields.io/coveralls/rawfunkmaharishi/purdie.svg?style=flat-square)](https://coveralls.io/r/rawfunkmaharishi/purdie)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/rawfunkmaharishi/purdie.svg?style=flat-square)](https://codeclimate.com/github/rawfunkmaharishi/purdie)
5
+ [![Gem Version](http://img.shields.io/gem/v/purdie.svg?style=flat-square)](https://rubygems.org/gems/purdie)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://rawfunkmaharishi.mit-license.org)
7
+ [![Badges](http://img.shields.io/:badges-7/7-ff6799.svg?style=flat-square)](https://github.com/badges/badgerbadgerbadger)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'cucumber/rake/task'
4
+ require 'coveralls/rake/task'
5
+
6
+ Coveralls::RakeTask.new
7
+ RSpec::Core::RakeTask.new
8
+ Cucumber::Rake::Task.new
9
+
10
+ task :default => [:spec, :cucumber, 'coveralls:push']
data/bin/purdie ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'purdie/cli'
4
+ Purdie::CLI.start
@@ -0,0 +1,11 @@
1
+ source-dir: _sources
2
+ output-dir: _data
3
+
4
+ soundcloud:
5
+ host: https://api.soundcloud.com
6
+
7
+ license-lookups:
8
+ cc-by-nc-sa:
9
+ short-name: BY-NC-SA
10
+ full-name: Attribution-NonCommercial-ShareAlike
11
+ url: http://creativecommons.org/licenses/by-nc-sa/4.0/
@@ -0,0 +1 @@
1
+ https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
@@ -0,0 +1,44 @@
1
+ @vcr
2
+ Feature: Soundcloud
3
+
4
+ Scenario: Generate SoundCloud YAML
5
+ Given a file named "_sources/sounds.csv" with:
6
+ """
7
+ https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
8
+ """
9
+ When I successfully run `purdie fetch -c ../../.purdie`
10
+ Then a file named "_data/sounds.yaml" should exist
11
+ And the file "_data/sounds.yaml" should contain:
12
+ """
13
+ - title: Hexaflexagon
14
+ id: 193008299
15
+ location: Islington Academy
16
+ date: '2015-02-18'
17
+ license: Attribution-NonCommercial-ShareAlike
18
+ license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
19
+ """
20
+
21
+
22
+ Scenario: Generate SoundCloud YAML for multiple tracks
23
+ Given a file named "_sources/sounds.csv" with:
24
+ """
25
+ https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
26
+ https://soundcloud.com/rawfunkmaharishi/junalbandi-3
27
+ """
28
+ When I successfully run `purdie fetch -c ../../.purdie`
29
+ Then a file named "_data/sounds.yaml" should exist
30
+ And the file "_data/sounds.yaml" should contain:
31
+ """
32
+ - title: Hexaflexagon
33
+ id: 193008299
34
+ location: Islington Academy
35
+ date: '2015-02-18'
36
+ license: Attribution-NonCommercial-ShareAlike
37
+ license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
38
+ - title: Hexaflexagon
39
+ id: 193008299
40
+ location: Islington Academy
41
+ date: '2015-02-18'
42
+ license: Attribution-NonCommercial-ShareAlike
43
+ license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
44
+ """
@@ -0,0 +1,11 @@
1
+ ENV['RACK_ENV'] = 'test'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', '..', 'lib/purdie.rb')
4
+
5
+ require 'aruba/cucumber'
6
+ require 'rspec'
7
+
8
+ require 'coveralls'
9
+ Coveralls.wear_merged!
10
+
11
+ $fixtures = File.join(File.dirname(__FILE__), 'fixtures/')
@@ -0,0 +1,2 @@
1
+ soundcloud:
2
+ client_id: 123456
File without changes
@@ -0,0 +1,12 @@
1
+ require 'vcr'
2
+ require 'webmock/cucumber'
3
+
4
+ VCR.configure do |c|
5
+ c.default_cassette_options = { :record => :once }
6
+ c.cassette_library_dir = 'fixtures/vcr'
7
+ c.hook_into :webmock
8
+ end
9
+
10
+ VCR.cucumber_tags do |t|
11
+ t.tag '@vcr', use_scenario_name: true
12
+ end
@@ -0,0 +1,2 @@
1
+ soundcloud:
2
+ client_id: 123456
@@ -0,0 +1 @@
1
+ https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
@@ -0,0 +1,32 @@
1
+ require 'purdie'
2
+
3
+ module Purdie
4
+ class Bernard
5
+ attr_reader :config
6
+
7
+ def initialize config_file = File.join(File.dirname(__FILE__), '..', '.purdie')
8
+ @config = Config.new config_file
9
+ end
10
+
11
+ def fetch
12
+ s = Purdie::Services::SoundCloud.new @config
13
+ sounds = []
14
+
15
+ sources = Dir.entries(@config['source-dir']).select { |e| e !~ /^\./ }
16
+ sources.each do |source|
17
+ lines = File.readlines "#{@config['source-dir']}/#{source}"
18
+ lines.each do |line|
19
+ case line
20
+ when /soundcloud/
21
+ sounds.push s.refine line
22
+ end
23
+ end
24
+ end
25
+
26
+ FileUtils.mkdir @config['output-dir']
27
+ sf = File.open '_data/sounds.yaml', 'w'
28
+ sf.write sounds.to_yaml
29
+ sf.close
30
+ end
31
+ end
32
+ end
data/lib/purdie/cli.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'purdie'
2
+
3
+ module Purdie
4
+ class CLI < Thor
5
+ desc 'version', 'Print purdie version'
6
+ def version
7
+ puts "purdie version #{VERSION}"
8
+ end
9
+ map %w(-v --version) => :version
10
+
11
+ desc 'fetch', 'Fetch the data'
12
+ method_option :config,
13
+ :aliases => '-c',
14
+ :desc => 'Specify config file',
15
+ :default => '~/.purdie'
16
+ def fetch
17
+ b = Bernard.new options[:config]
18
+ b.fetch
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'purdie'
2
+
3
+ module Purdie
4
+ class Config
5
+ def initialize config_file = nil
6
+ @conf = YAML.load File.read File.join(File.dirname(__FILE__), '..', '..', 'config/defaults.yaml')
7
+
8
+ if config_file
9
+ @conf = @conf.deep_merge YAML.load File.read config_file
10
+ end
11
+ end
12
+
13
+ def [] key
14
+ @conf[key]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,40 @@
1
+ require 'purdie'
2
+
3
+ Dotenv.load '.purdie'
4
+
5
+ module Purdie
6
+ module Services
7
+ class SoundCloud
8
+ def initialize config
9
+ @config = config
10
+ end
11
+
12
+ def all_tracks
13
+ @all_tracks ||= begin
14
+ url = "#{@config['soundcloud']['host']}/users/#{ENV['SOUNDCLOUD_USER_ID']}/tracks?client_id=#{ENV['SOUNDCLOUD_CLIENT_ID']}"
15
+ response = HTTParty.get url
16
+ JSON.parse response.body
17
+ end
18
+ end
19
+
20
+ def get_track url
21
+ all_tracks.select do |track|
22
+ Purdie.strip_scheme(track['permalink_url']) == Purdie.strip_scheme(url)
23
+ end[0]
24
+ end
25
+
26
+ def refine url
27
+ track = get_track url
28
+ results = {}
29
+ results['title'] = track['title']
30
+ results['id'] = track['id']
31
+ results['location'] = track['description']
32
+ results['date'] = "%4d-%02d-%02d" % [ track['release_year'], track['release_month'], track['release_day'] ]
33
+ results['license'] = @config['license-lookups'][track['license']]['full-name']
34
+ results['license_url'] = @config['license-lookups'][track['license']]['url']
35
+
36
+ results
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Purdie
2
+ VERSION = "0.0.1"
3
+ end
data/lib/purdie.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'thor'
2
+ require 'yaml'
3
+ require 'deep_merge'
4
+ require 'httparty'
5
+ require 'dotenv'
6
+
7
+ require 'purdie/version'
8
+ require 'purdie/bernard'
9
+ require 'purdie/config'
10
+
11
+ require 'purdie/services/soundcloud'
12
+
13
+ module Purdie
14
+ def Purdie.strip_scheme url
15
+ url.match(/http[s]?:\/\/(.*)/)[1]
16
+ end
17
+ end
data/purdie.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'purdie/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'purdie'
8
+ spec.version = Purdie::VERSION
9
+ spec.authors = ['pikesley']
10
+ spec.email = ['github@orgraphone.org']
11
+ spec.summary = %q{Capture metadata from Flickr, SoundCloud et al for when we're building a static site}
12
+ spec.description = %q{Capture metadata from Flickr, SoundCloud et al for when we're building a static site}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'thor', '~> 0.19'
22
+ spec.add_dependency 'httparty', '~> 0.13'
23
+ spec.add_dependency 'deep_merge', '~> 1.0'
24
+ spec.add_dependency 'dotenv', '~> 1.0'
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.7'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.2'
29
+ spec.add_development_dependency 'aruba', '~> 0.5'
30
+ spec.add_development_dependency 'guard', '~> 2.12'
31
+ spec.add_development_dependency 'guard-rspec', '~> 4.5'
32
+ spec.add_development_dependency 'guard-cucumber', '~> 1.5'
33
+ spec.add_development_dependency 'terminal-notifier-guard', '~> 1.6'
34
+ spec.add_development_dependency 'coveralls', '~> 0.7'
35
+ spec.add_development_dependency 'webmock', '~> 1.20'
36
+ spec.add_development_dependency 'vcr', '~> 2.9'
37
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module Purdie
4
+ describe Config do
5
+ it 'has defaults' do
6
+ c = Config.new
7
+ expect(c['output-dir']).to eq '_data'
8
+ end
9
+
10
+ it 'has custom stuff alongside defaults' do
11
+ c = Config.new File.join(File.dirname(__FILE__), '..', 'features/support/fixtures/config/purdie')
12
+ expect(c['soundcloud']['host']).to eq 'https://api.soundcloud.com'
13
+ expect(c['soundcloud']['client_id']).to eq 123456
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module Purdie
4
+ describe Bernard do
5
+ it 'has config' do
6
+ b = Bernard.new File.join(File.dirname(__FILE__), '..', 'features/support/fixtures/config/purdie')
7
+ expect(b.config['soundcloud']['client_id']).to eq 123456
8
+ expect(b.config['output-dir']).to eq '_data'
9
+ end
10
+
11
+ it 'connects to soundcloud', :vcr do
12
+ b = Bernard.new File.join(File.dirname(__FILE__), '..', '.purdie')
13
+ end
14
+
15
+ it 'strips a scheme' do
16
+ expect(Purdie.strip_scheme 'http://foo.bar/stuff').to eq 'foo.bar/stuff'
17
+ expect(Purdie.strip_scheme 'https://bar.foo/stuff').to eq 'bar.foo/stuff'
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ module Purdie
4
+ module Services
5
+ describe SoundCloud do
6
+ before :each do
7
+ @sc = SoundCloud.new Config.new $config_file
8
+ end
9
+
10
+ it 'connects to SoundCloud', :vcr do
11
+ expect(@sc.all_tracks).to be_a Array
12
+ end
13
+
14
+ it 'extracts a track' do
15
+ track = @sc.get_track 'https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1'
16
+ expect(track).to be_a Hash
17
+ expect(track['id']). to eq 193008299
18
+ end
19
+
20
+ it 'refines the data' do
21
+ refined = @sc.refine 'https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1'
22
+ expect(refined).to eq({
23
+ "title"=>"Hexaflexagon",
24
+ "id"=>193008299,
25
+ "location"=>"Islington Academy",
26
+ "date"=>"2015-02-18",
27
+ "license"=>"Attribution-NonCommercial-ShareAlike",
28
+ "license_url"=>"http://creativecommons.org/licenses/by-nc-sa/4.0/"})
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,18 @@
1
+ require 'purdie'
2
+ require_relative 'support/vcr_setup'
3
+
4
+ RSpec.configure do |config|
5
+ config.expect_with :rspec do |expectations|
6
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
7
+ end
8
+
9
+ config.mock_with :rspec do |mocks|
10
+ mocks.verify_partial_doubles = true
11
+ end
12
+
13
+ config.filter_run :focus
14
+ config.run_all_when_everything_filtered = true
15
+ config.order = :random
16
+ end
17
+
18
+ $config_file = File.join(File.dirname(__FILE__), '..', '.purdie')
@@ -0,0 +1,19 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ #the directory where your cassettes will be saved
5
+ c.cassette_library_dir = 'spec/vcr'
6
+ # your HTTP request service. You can also use fakeweb, webmock, and more
7
+ c.hook_into :webmock
8
+ c.default_cassette_options = { :record => :once }
9
+ c.debug_logger = File.open('/tmp/wtfvcr', 'w')
10
+ c.allow_http_connections_when_no_cassette = true
11
+
12
+ [
13
+ 'SOUNDCLOUD_CLIENT_ID'
14
+ ].each do |env_var|
15
+ c.filter_sensitive_data("<#{env_var}>") { ENV[env_var] }
16
+ end
17
+
18
+ c.configure_rspec_metadata!
19
+ end