bulkippt 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.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .rvmrc
7
+ .rspec
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bulkippt.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Johnny Boursiquot
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,29 @@
1
+ # Bulkippt
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'bulkippt'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install bulkippt
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => [:spec]
6
+
7
+ desc 'Runs all specs'
8
+ RSpec::Core::RakeTask.new(:spec)
data/bulkippt.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bulkippt/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "bulkippt"
8
+ gem.version = Bulkippt::VERSION
9
+ gem.authors = ["Johnny Boursiquot"]
10
+ gem.email = ["jboursiquot@gmail.com"]
11
+ gem.description = %q{Imports bookmarks (url, title, etc) into your kippt.com account in bulk}
12
+ gem.summary = %q{Imports bookmarks (url, title, etc) into your kippt.com account in bulk}
13
+ gem.homepage = "https://github.com/jboursiquot/bulkippt"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency 'kippt','~> 1.1'
21
+
22
+ gem.add_development_dependency 'rake','~> 0.9'
23
+ gem.add_development_dependency 'rspec','~> 2.11'
24
+ gem.add_development_dependency 'fivemat', '~> 1.1'
25
+ end
data/lib/bulkippt.rb ADDED
@@ -0,0 +1,79 @@
1
+ require "bulkippt/version"
2
+
3
+ require 'csv'
4
+ require 'logger'
5
+
6
+ module Bulkippt
7
+
8
+ class Loader
9
+
10
+ attr_reader :service, :logger
11
+
12
+ def initialize(service, logger = Logger.new(STDOUT))
13
+ @service = service
14
+ @logger = logger
15
+ end
16
+
17
+ def credentials_valid?
18
+ begin
19
+ @account = @service.account
20
+ true
21
+ rescue Kippt::APIError => e
22
+ false
23
+ rescue => e
24
+ @logger.error e.message
25
+ false
26
+ end
27
+ end
28
+
29
+ def extract_bookmarks(file_path)
30
+ begin
31
+ raise Exception, "CSV not found: #{file_path}" if !File.exists?(file_path)
32
+
33
+ @csv = CSV.read(file_path, {headers: true})
34
+ headers = @csv.headers.map(&:downcase) #normalize colum titles
35
+
36
+ #url and title are required, description and folder are not
37
+ raise Exception, "Missing 'url' column" unless headers.include? 'url'
38
+ raise Exception, "Missing 'title' column" unless headers.include? 'title'
39
+
40
+ bookmarks = []
41
+ @csv.each do |b|
42
+ row = {}
43
+ b.to_hash.each_pair do |k,v|
44
+ row.merge!({k.downcase => v})
45
+ end
46
+ bookmark = OpenStruct.new(url: row['url'], title: row['title'])
47
+ bookmark.description = row['description'] if headers.include? 'description'
48
+ bookmark.folder = row['folder'] if headers.include? 'folder'
49
+ bookmarks << bookmark
50
+ end
51
+ bookmarks
52
+ rescue => e
53
+ @logger.error e.message
54
+ end
55
+ end
56
+
57
+ def submit_bookmarks(bookmarks)
58
+ submitted = []
59
+ begin
60
+ bookmarks.each do |bookmark|
61
+ clip = @service.clips.build
62
+ clip.url = bookmark.url
63
+ clip.title = bookmark.title
64
+ clip.notes = bookmark.description
65
+ if clip.save
66
+ submitted << clip
67
+ @logger.info "SUCCESS: #{clip.title} #{clip.url}"
68
+ else
69
+ @logger.error "FAILURE: #{clip.title} #{clip.url} | #{clip.errors[]}"
70
+ end
71
+ end
72
+ submitted
73
+ rescue => e
74
+ @logger.error e.message
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Bulkippt
2
+ VERSION = "0.0.1"
3
+ end
File without changes
@@ -0,0 +1 @@
1
+ URL,Title,Description,Folder
@@ -0,0 +1,59 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe "Bulkippt" do
4
+
5
+ context "when asked to verify credentials" do
6
+
7
+ it "should detect that a given set of credentials is incorrect" do
8
+ Bulkippt::Loader.new(Bulkippt::FakeService.new('invalid', 'invalid')).credentials_valid?.should be_false
9
+ end
10
+
11
+ it "should detect that a given set of credentials is correct" do
12
+ Bulkippt::Loader.new(Bulkippt::FakeService.new('valid', 'valid')).credentials_valid?.should be_true
13
+ end
14
+
15
+ end
16
+
17
+ context "when parsing an invalid CSV" do
18
+
19
+ let :bad_csv do
20
+ File.expand_path './spec/data/empty.csv'
21
+ end
22
+
23
+ it "should raise an error when it can't find the file specified" do
24
+ loader = Bulkippt::Loader.new(Bulkippt::FakeService.new('valid','valid'))
25
+ expect {loader.extract_bookmarks('/does/not/exist.csv')}.to raise_error
26
+ end
27
+
28
+ it "should raise an error when missing the require url and title columns" do
29
+ loader = Bulkippt::Loader.new(Bulkippt::FakeService.new('valid', 'valid'))
30
+ expect { loader.extract_bookmarks bad_csv }.to raise_error
31
+ end
32
+
33
+ end
34
+
35
+ context "when parsing a valid CSV" do
36
+
37
+ let :good_csv do
38
+ File.expand_path './spec/data/good.csv'
39
+ end
40
+
41
+ it "should find all the bookmarks" do
42
+ loader = Bulkippt::Loader.new(Bulkippt::FakeService.new('valid', 'valid'))
43
+ clips = loader.extract_bookmarks good_csv
44
+ clips.class.should == Array
45
+ clips.size.should >= 3
46
+ end
47
+
48
+ it "should use the service to submit the bookmarks" do
49
+ loader = Bulkippt::Loader.new(Bulkippt::FakeService.new('valid', 'valid'))
50
+ bookmarks = loader.extract_bookmarks good_csv
51
+ saved = loader.submit_bookmarks bookmarks
52
+ saved.class.should == Array
53
+ saved.first.url.should == 'http://www.kippt.com'
54
+ saved.first.title.should == 'Kippt'
55
+ end
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,43 @@
1
+ %w{kippt json}.each{ |lib| require lib}
2
+ %w{bulkippt}.each { |file| require File.join(File.dirname(__FILE__),"../lib", file)}
3
+
4
+ module Bulkippt
5
+
6
+ class FakeService
7
+
8
+ attr_reader :username, :token, :clips
9
+
10
+ def initialize(username, token)
11
+ @username = username
12
+ @token = token
13
+ @clips = Clips.new
14
+ end
15
+
16
+ def account
17
+ if credentials_valid?(@username, @token)
18
+ {username: @username, token: @token}.to_json
19
+ else
20
+ raise Kippt::APIError, "Can't find an user with this username and api_key"
21
+ end
22
+ end
23
+
24
+ def credentials_valid?(username, token)
25
+ return false if username != 'valid' && @token != 'valid'
26
+ true
27
+ end
28
+
29
+ end
30
+
31
+ class Clips
32
+ def build
33
+ Clip.new
34
+ end
35
+ end
36
+
37
+ class Clip < OpenStruct
38
+ def save
39
+ self
40
+ end
41
+ end
42
+
43
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bulkippt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Johnny Boursiquot
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: kippt
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.9'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.9'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.11'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.11'
62
+ - !ruby/object:Gem::Dependency
63
+ name: fivemat
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.1'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.1'
78
+ description: Imports bookmarks (url, title, etc) into your kippt.com account in bulk
79
+ email:
80
+ - jboursiquot@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - Guardfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bulkippt.gemspec
92
+ - lib/bulkippt.rb
93
+ - lib/bulkippt/version.rb
94
+ - spec/data/empty.csv
95
+ - spec/data/good.csv
96
+ - spec/lib/bulkippt_spec.rb
97
+ - spec/spec_helper.rb
98
+ homepage: https://github.com/jboursiquot/bulkippt
99
+ licenses: []
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ none: false
112
+ requirements:
113
+ - - ! '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 1.8.24
119
+ signing_key:
120
+ specification_version: 3
121
+ summary: Imports bookmarks (url, title, etc) into your kippt.com account in bulk
122
+ test_files:
123
+ - spec/data/empty.csv
124
+ - spec/data/good.csv
125
+ - spec/lib/bulkippt_spec.rb
126
+ - spec/spec_helper.rb