pitcher 0.0.2

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: 2e3ee77f4fb83a1cbe86eae678d661dbaab44cde
4
+ data.tar.gz: cd544bc218bdc783f4cf16dd9fb7c04932a537c4
5
+ SHA512:
6
+ metadata.gz: 2801d727896f0b0e6764f7c24ffa1a7166da8c2e5fb564948d325564ec348c4e68f4442856af034299908bf7ba44842726e97638b6238f6848b6e4a58ee0bddf
7
+ data.tar.gz: bf91c34dd16816eb2813074b5d4df15d3e37b2105d32710ade15587ec4ed04bf634b93657f439f3142f80bbafb2665ef6f3dc1088b3179d983aebc88d413d480
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pitcher'
4
+ require 'pitcher/settings'
5
+
6
+ pitcher = Pitcher::Pitcher.new
7
+
8
+ pitcheropts = Pitcher::PitcherOpts.new
9
+ options = pitcheropts::parse(ARGV)
10
+
11
+
12
+ if (!options[:settings] || !options[:csv])
13
+ puts 'The --settings and --csv paramters are required'
14
+ exit
15
+ end
16
+
17
+ if (options[:settings])
18
+ settings = Settings.new(options[:settings])
19
+ p settings
20
+ else
21
+ exit
22
+ end
23
+
24
+ if (options[:csv])
25
+ csv = pitcher.load_csv(options[:csv])
26
+ pitcher.create_message(csv,settings)
27
+ else
28
+ exit
29
+ end
@@ -0,0 +1,59 @@
1
+ require 'pitcher/version'
2
+ require 'pitcher/options'
3
+ require 'savon'
4
+ require 'CSV'
5
+
6
+ module Pitcher
7
+ class Pitcher
8
+ attr_accessor :message
9
+
10
+ # load the csv and parse
11
+ def load_csv(file)
12
+ metadata = File.open(file, 'r')
13
+ metadata_parsed = CSV.new(metadata, :headers => true, :header_converters => :symbol)
14
+ return metadata_parsed
15
+ end
16
+
17
+ def create_message(metadata_parsed,settings)
18
+ self.message = {}
19
+ self.message[:cdmurl] = settings.cdmurl
20
+ self.message[:username] = settings.username
21
+ self.message[:password] = settings.password
22
+ self.message[:license] = settings.license
23
+
24
+ metadata_parsed.each do |line|
25
+ self.message[:action] = line[:action]
26
+ self.message[:collection] = line[:collection]
27
+
28
+ contentdm_record = {
29
+ 'field' => 'dmrecord' ,
30
+ 'value' => line[:cdmnumber]
31
+ }
32
+
33
+ file_name = {
34
+ 'field' => line[:field],
35
+ 'value' => line[:value]
36
+ }
37
+
38
+ metadata = {'metadata' => [contentdm_record, file_name]}
39
+
40
+ metadataList = {'metadataList' => metadata}
41
+
42
+ self.message[:metadata] = metadataList
43
+ # Define the server creds and the alias for the collection you want to use
44
+ send_message(self.message)
45
+ end
46
+ end
47
+
48
+ def send_message(message)
49
+ # Initialize the SOAP client with the catcher service url
50
+ client = Savon.client(
51
+ wsdl: 'https://worldcat.org/webservices/contentdm/catcher/6.0/CatcherService.wsdl',
52
+ pretty_print_xml: true,
53
+ log: true
54
+ )
55
+ # Create the hash that will be sent as a message to the service with the creds and data above
56
+ client.call(:process_conten_tdm, message: message)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,30 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Pitcher
5
+ class PitcherOpts
6
+
7
+ def parse(args)
8
+ options = OpenStruct.new
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = 'Usage: pitcher -csv /path/to/csv.file'
12
+
13
+ opts.on("-csv", "--csv", 'Path to CSV file') do |csv|
14
+ options.csv = csv
15
+ end
16
+
17
+ opts.on("-settings", "--settings", "Path to the settings file") do |settings|
18
+ options.settings = settings
19
+ end
20
+
21
+ opts.on("-h", "--help", "Pitcher Help") do
22
+ puts opts
23
+ exit
24
+ end
25
+
26
+ end.parse!
27
+ options
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ require 'yaml'
2
+
3
+ class Settings
4
+ attr_accessor :cdmurl
5
+ attr_accessor :username
6
+ attr_accessor :password
7
+ attr_accessor :license
8
+ attr_accessor :settings
9
+
10
+ def initialize(file)
11
+ settings = YAML.load_file(file)
12
+ @cdmurl = settings['cdmurl']
13
+ @username = settings['username']
14
+ @password = settings['password']
15
+ @license = settings['license']
16
+ end
17
+
18
+
19
+ end
20
+
@@ -0,0 +1,3 @@
1
+ module Pitcher
2
+ VERSION = "0.0.2"
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pitcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jamie Little
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-07 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: savon
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - jamielittle@outlook.com
58
+ executables:
59
+ - pitcher
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - lib/pitcher/options.rb
64
+ - lib/pitcher/settings.rb
65
+ - lib/pitcher/version.rb
66
+ - lib/pitcher.rb
67
+ - bin/pitcher
68
+ homepage: ''
69
+ licenses:
70
+ - BSD
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.0.2
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: CLI utility to work with CONTENTdm's Catcher API
92
+ test_files: []