elibri_connect 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/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Elibri Connect gem #
2
+
3
+ ## Continuous integration status ##
4
+ ### Elibri dependencies: ###
5
+ Elibri Xml Versions: [![Build Status](https://secure.travis-ci.org/elibri/elibri_xml_versions.png?branch=master)](http://travis-ci.org/elibri/elibri_xml_versions)
6
+ Elibri Onix Mocks: [![Build Status](https://secure.travis-ci.org/elibri/elibri_onix_mocks.png?branch=master)](http://travis-ci.org/elibri/elibri_onix_mocks)
7
+ Acts as Elibri Product: [![Build Status](https://secure.travis-ci.org/elibri/acts_as_elibri_product.png?branch=master)](http://travis-ci.org/elibri/acts_as_elibri_product)
8
+
9
+ ### Elibri Connect: ###
10
+ [![Build Status](https://secure.travis-ci.org/elibri/elibri_connect.png?branch=master)](http://travis-ci.org/elibri/elibri_connect)
11
+
12
+
13
+ ## Description ##
14
+
15
+ Gem designed to allow easy addition of elibri based product system to your application.
16
+ Currently tested and support only on REE - due to dependencies.
17
+
18
+ ## Usage ##
19
+
20
+ * add `gem 'elibri_connect'` to you Gemfile
21
+ * run `bundle install`
22
+
23
+ Now - depending on your situation you may choose one of four options:
24
+
25
+ * `rails generate elibri:connect:config` to create only configuration file in initializers, in which you need to supply your own user/password combination.
26
+ * `rails generate elibri:connect:db_structure` to create db structure and models (product, contributor and product_text), which will have turned on elibri synchronisation.
27
+ * `rails generate elibri:connect:whenever` to create config/schedule.rb file, which will invoke elibri sync every 6 hours. It will overwrite your actual config/schedule.rb - so please be careful.
28
+ * `rails generate elibri:connect:install` which will invoke all three previous generators.
29
+
30
+ If you have working application, and you need to add support to existing product model - please look here for more information about adding acts_as_elibri_product declaration to model (including traverse vector examples): [elibri/acts_as_elibri_product](https://github.com/elibri/acts_as_elibri_product)
31
+
32
+ After creation of config file, gem will provide you with rake task: `rake elibri:update_products` which will connect to elibri, download new and update existing product. You can also use it from your code using `Elibri::Connect.update_products!` method.
33
+ If you need to access raw api client - you can get it by invoking `Elibri::Connect.api_client`.
34
+
35
+ Gem has additional mode of operation called test_mode - you can get into it, by setting `test_mode=true` inside configuration file. When using it your application will not connect to elibri, instead it will use elibri_xml_mocks to mock and create product for your app.
36
+
37
+ ## Anatomy of config file ##
38
+
39
+ Config file looks like this, and needs to be in config/initializers directory (generate command can provide one for you):
40
+
41
+ ```ruby
42
+ Elibri::Connect.setup do |config|
43
+ config.login = your elibri api login here
44
+ config.password = your elibri api password here
45
+ config.api_version = 'v1' #api_version - doesn't need to be changed
46
+ config.onix_dialect = '3.0.1' #onix_dialect - doesn't need to be changed
47
+ config.product_model = :product #if you use other model than product - you need to set different name here
48
+ config.test_mode = true #- add this line to config if you want to avoid connecting to elibri and use mocked data
49
+ end
50
+ ```
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'ElibriConnect'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ desc "Running specs"
29
+ task :spec do |t|
30
+ exec "cd spec/dummy && bundle exec rake db:create:all && bundle exec rake db:migrate && bundle exec rake db:test:prepare && cd .. && bundle exec rspec elibri_connect_spec.rb"
31
+ end
32
+
33
+ task :default => ["spec"]
34
+
@@ -0,0 +1,39 @@
1
+ require 'acts_as_elibri_product'
2
+ require 'elibri_api_client'
3
+ require 'elibri_onix_mocks'
4
+
5
+ require 'elibri_connect/railtie'
6
+
7
+ module Elibri
8
+ module Connect
9
+
10
+ class << self
11
+ attr_accessor :login, :password, :api_version, :onix_dialect, :test_mode, :product_model
12
+ end
13
+
14
+ def self.setup(&block)
15
+ yield self
16
+ end
17
+
18
+ def self.api_client
19
+ Elibri::ApiClient.new(:login => login, :password => password,
20
+ :api_version => api_version, :onix_dialect => onix_dialect)
21
+ end
22
+
23
+ def self.update_products!
24
+ if test_mode
25
+ book = Elibri::XmlMocks::Examples.book_example
26
+ (self.product_model).to_s.capitalize.constantize.batch_create_or_update_from_elibri(Elibri::ONIX::XMLGenerator.new(book).to_s)
27
+ else
28
+ api = Elibri::ApiClient.new(:login => login, :password => password,
29
+ :api_version => api_version, :onix_dialect => onix_dialect)
30
+ api.refill_all_queues!
31
+ while (queue = api.pending_queues.find { |q| q.name == 'meta' })
32
+ response = api.pop_from_queue('meta', :count => 25)
33
+ (self.product_model).to_s.capitalize.constantize.batch_create_or_update_from_elibri(response.onix)
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,11 @@
1
+ require 'elibri_connect'
2
+ require 'rails'
3
+ module ElibriConnect
4
+ class Railtie < Rails::Railtie
5
+ railtie_name :elibri_connect
6
+
7
+ rake_tasks do
8
+ load "tasks/elibri_connect_tasks.rake"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ElibriConnect
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,17 @@
1
+ module Elibri
2
+ module Connect
3
+ class ConfigGenerator < Rails::Generators::Base
4
+ desc "This generator creates an elibri configuration file at config/initializers"
5
+ def create_config_file
6
+ create_file "config/initializers/elibri_config.rb",
7
+ %Q{Elibri::Connect.setup do |config|
8
+ config.login = 'login' #INSERT YOUR LOGIN HERE
9
+ config.password = 'password' #INSERT YOUR PASSWORD HERE
10
+ config.api_version = 'v1'
11
+ config.onix_dialect = '3.0.1'
12
+ config.product_model = :product #IF NEEDED CHANGE MODEL NAME HERE
13
+ end}
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,96 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module Elibri
5
+ module Connect
6
+ class DbStructureGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
+ source_root File.expand_path('../templates', __FILE__)
9
+
10
+ desc "This generator creates basic models and database structure for using elibri"
11
+ def create_elibri_db_structure
12
+ create_file "app/models/contributor.rb",
13
+ %Q{class Contributor < ActiveRecord::Base
14
+
15
+ belongs_to :product, :touch => true
16
+
17
+ attr_accessible :import_id, :role_name, :role, :from_language, :full_name, :title, :first_name,
18
+ :last_name_prefix, :last_name, :last_name_postfix, :biography
19
+ end}
20
+ create_file "app/models/product_text.rb",
21
+ %Q{class ProductText < ActiveRecord::Base
22
+
23
+ belongs_to :product, :touch => true
24
+
25
+ attr_accessible :import_id, :text, :text_type, :text_author, :source_title, :resource_link
26
+
27
+ end}
28
+ create_file "app/models/product.rb",
29
+ %Q[class Product < ActiveRecord::Base
30
+
31
+ with_options :autosave => true, :dependent => :destroy do |product|
32
+ product.has_many :contributors
33
+ product.has_many :product_texts
34
+ product.has_one :imprint
35
+ end
36
+
37
+ attr_accessible :isbn, :title, :full_title, :trade_title, :original_title, :publication_year,
38
+ :publication_month, :publication_day, :number_of_pages, :width, :height,
39
+ :cover_type, :edition_statement, :audience_age_from, :audience_age_to,
40
+ :price_amount, :vat, :current_state, :product_form, :old_xml
41
+
42
+ #on left side elibri attributes, on right side our name of attribute
43
+ acts_as_elibri_product :record_reference => :record_reference,
44
+ :isbn13 => :isbn,
45
+ :title => :title,
46
+ :full_title => :full_title,
47
+ :trade_title => :trade_title,
48
+ :original_title => :original_title,
49
+ :number_of_pages => :number_of_pages,
50
+ :duration => :duration,
51
+ :width => :width,
52
+ :height => :height,
53
+ :cover_type => :cover_type,
54
+ :pkwiu => :pkwiu,
55
+ :edition_statement => :edition_statement,
56
+ :cover_price => :price_amount,
57
+ :vat => :vat,
58
+ :product_form => :product_form,
59
+ :no_contributor? => :no_contributor,
60
+ :unnamed_persons? => :unnamed_persons,
61
+ :contributors => { #name in elibri
62
+ :contributors => { #name in our db
63
+ :id => :import_id,
64
+ :role_name => :role_name,
65
+ :role => :role,
66
+ :from_language => :from_language,
67
+ :person_name => :full_name,
68
+ :titles_before_names => :title,
69
+ :names_before_key => :first_name,
70
+ :prefix_to_key => :last_name_prefix,
71
+ :key_names => :last_name,
72
+ :names_after_key => :last_name_postfix,
73
+ :biographical_note => :biography
74
+ }
75
+ },
76
+ :text_contents => {
77
+ :product_texts => {
78
+ :id => :import_id,
79
+ :text => :text,
80
+ :type_name => :text_type,
81
+ :author => :text_author,
82
+ :source_title => :source_title,
83
+ :source_url => :resource_link
84
+ }
85
+ }
86
+ ]
87
+ migration_template "create_elibri_structure.rb", "db/migrate/create_elibri_structure.rb"
88
+ end
89
+
90
+ def self.next_migration_number(path)
91
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,59 @@
1
+ class CreateElibriStructure < ActiveRecord::Migration
2
+
3
+ def change
4
+ create_table :contributors do |t|
5
+ t.integer :import_id
6
+ t.integer :product_id
7
+ t.string :role_name
8
+ t.string :role
9
+ t.string :from_language
10
+ t.string :full_name
11
+ t.string :title
12
+ t.string :first_name
13
+ t.string :last_name_prefix
14
+ t.string :last_name
15
+ t.string :last_name_postfix
16
+ t.text :biography
17
+
18
+ t.timestamps
19
+ end
20
+
21
+ create_table :product_texts do |t|
22
+ t.integer :import_id
23
+ t.integer :product_id
24
+ t.text :text
25
+ t.string :text_type
26
+ t.string :text_author
27
+ t.string :source_title
28
+ t.string :resource_link
29
+
30
+ t.timestamps
31
+ end
32
+
33
+ create_table :products do |t|
34
+ t.string :record_reference, :null => false
35
+ t.string :isbn
36
+ t.string :title
37
+ t.string :full_title
38
+ t.string :trade_title
39
+ t.string :original_title
40
+ t.integer :number_of_pages
41
+ t.integer :duration
42
+ t.integer :width
43
+ t.integer :height
44
+ t.string :cover_type
45
+ t.string :edition_statement
46
+ t.string :price_amount
47
+ t.integer :vat
48
+ t.string :pkwiu
49
+ t.string :current_state
50
+ t.string :product_form
51
+ t.boolean :preview_exists, :default => false
52
+ t.boolean :no_contributor, :default => false
53
+ t.boolean :unnamed_persons, :default => false
54
+ t.text :old_xml
55
+ t.timestamps
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,14 @@
1
+ module Elibri
2
+ module Connect
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ desc "This generator installs and elibri product system in application - including db structure, models and config file"
6
+ def install
7
+ Rails::Generators.invoke("elibri:connect:config")
8
+ Rails::Generators.invoke("elibri:connect:db_structure")
9
+ Rails::Generators.invoke("elibri:connect:whenever")
10
+ rake('db:migrate')
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ module Elibri
2
+ module Connect
3
+ class WheneverGenerator < Rails::Generators::Base
4
+ desc "This generator creates an elibri whenever file, adding into cron and updating products every 6 hours"
5
+ def whenever
6
+ create_file "config/schedule.rb",
7
+ %Q{every 6.hours do
8
+ runner "Elibri::Connect.update_products!"
9
+ end}
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ # desc "Explaining what the task does"
2
+ # task :elibri_connect do
3
+ # # Task goes here
4
+ # end
5
+
6
+ namespace :elibri do
7
+ desc "Load products from elibri - creating and updating product where needed"
8
+ task :update_products do
9
+ Elibri::Connect.update_products!
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,191 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elibri_connect
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Piotr Szmielew
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-04-06 00:00:00 Z
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ prerelease: false
21
+ requirement: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ hash: 15
27
+ segments:
28
+ - 3
29
+ - 2
30
+ - 0
31
+ version: 3.2.0
32
+ version_requirements: *id001
33
+ name: rails
34
+ type: :runtime
35
+ - !ruby/object:Gem::Dependency
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ version_requirements: *id002
47
+ name: acts_as_elibri_product
48
+ type: :runtime
49
+ - !ruby/object:Gem::Dependency
50
+ prerelease: false
51
+ requirement: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ version_requirements: *id003
61
+ name: elibri_api_client
62
+ type: :runtime
63
+ - !ruby/object:Gem::Dependency
64
+ prerelease: false
65
+ requirement: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ version_requirements: *id004
75
+ name: elibri_onix_mocks
76
+ type: :runtime
77
+ - !ruby/object:Gem::Dependency
78
+ prerelease: false
79
+ requirement: &id005 !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ version_requirements: *id005
89
+ name: whenever
90
+ type: :runtime
91
+ - !ruby/object:Gem::Dependency
92
+ prerelease: false
93
+ requirement: &id006 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ version_requirements: *id006
103
+ name: sqlite3
104
+ type: :development
105
+ - !ruby/object:Gem::Dependency
106
+ prerelease: false
107
+ requirement: &id007 !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
116
+ version_requirements: *id007
117
+ name: rspec
118
+ type: :development
119
+ - !ruby/object:Gem::Dependency
120
+ prerelease: false
121
+ requirement: &id008 !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ hash: 3
127
+ segments:
128
+ - 0
129
+ version: "0"
130
+ version_requirements: *id008
131
+ name: rspec-rails
132
+ type: :development
133
+ description: |-
134
+ Gem designed to allow easy addition of elibri based product system to your application.
135
+ Currently tested and support only on REE - due to dependencies.
136
+ email:
137
+ - p.szmielew@ava.waw.pl
138
+ executables: []
139
+
140
+ extensions: []
141
+
142
+ extra_rdoc_files: []
143
+
144
+ files:
145
+ - lib/elibri_connect/railtie.rb
146
+ - lib/elibri_connect/version.rb
147
+ - lib/elibri_connect.rb
148
+ - lib/generators/elibri/connect/config/config_generator.rb
149
+ - lib/generators/elibri/connect/db_structure/db_structure_generator.rb
150
+ - lib/generators/elibri/connect/db_structure/templates/create_elibri_structure.rb
151
+ - lib/generators/elibri/connect/install/install_generator.rb
152
+ - lib/generators/elibri/connect/whenever/whenever_generator.rb
153
+ - lib/tasks/elibri_connect_tasks.rake
154
+ - MIT-LICENSE
155
+ - Rakefile
156
+ - README.md
157
+ homepage: http://elibri.com.pl
158
+ licenses: []
159
+
160
+ post_install_message:
161
+ rdoc_options: []
162
+
163
+ require_paths:
164
+ - lib
165
+ required_ruby_version: !ruby/object:Gem::Requirement
166
+ none: false
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ hash: 3
171
+ segments:
172
+ - 0
173
+ version: "0"
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ none: false
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ hash: 3
180
+ segments:
181
+ - 0
182
+ version: "0"
183
+ requirements: []
184
+
185
+ rubyforge_project:
186
+ rubygems_version: 1.8.17
187
+ signing_key:
188
+ specification_version: 3
189
+ summary: Gem designed to allow easy addition of elibri based product system to your application.
190
+ test_files: []
191
+