certificate-factory 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +3 -0
  3. data/.ruby-version +1 -0
  4. data/.travis.yml +19 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +154 -0
  7. data/LICENSE.md +10 -0
  8. data/README.md +54 -0
  9. data/Rakefile +114 -0
  10. data/certificate-factory.gemspec +33 -0
  11. data/env.example +3 -0
  12. data/lib/certificate-factory.rb +14 -0
  13. data/lib/certificate-factory/api.rb +19 -0
  14. data/lib/certificate-factory/certificate.rb +112 -0
  15. data/lib/certificate-factory/factory.rb +89 -0
  16. data/lib/certificate-factory/version.rb +3 -0
  17. data/spec/api_spec.rb +12 -0
  18. data/spec/cassettes/CertificateFactory_API/returns_the_correct_URL_for_a_dataset.yml +107 -0
  19. data/spec/cassettes/CertificateFactory_Certificate/keeps_trying_for_a_result_until_it_gets_one.yml +64 -0
  20. data/spec/cassettes/CertificateFactory_Certificate/requests_and_gets_a_certificate.yml +781 -0
  21. data/spec/cassettes/CertificateFactory_Certificate/requests_certificate_creation.yml +39 -0
  22. data/spec/cassettes/CertificateFactory_Certificate/returns_an_error_if_dataset_already_exists.yml +106 -0
  23. data/spec/cassettes/CertificateFactory_Factory/builds_certificates_correctly.yml +726 -0
  24. data/spec/cassettes/CertificateFactory_Factory/creates_the_correct_number_of_certificates_going_over_multiple_pages.yml +4900 -0
  25. data/spec/cassettes/CertificateFactory_Factory/creates_the_correct_number_of_certificates_when_querying_a_single_page.yml +696 -0
  26. data/spec/cassettes/CertificateFactory_Factory/stops_when_it_gets_to_the_end_of_a_feed.yml +126 -0
  27. data/spec/certificate_spec.rb +93 -0
  28. data/spec/factory_spec.rb +88 -0
  29. data/spec/fixtures/certificate.json +1 -0
  30. data/spec/fixtures/feed.atom +97 -0
  31. data/spec/fixtures/one-page.atom +23 -0
  32. data/spec/fixtures/single-feed-1.atom +26 -0
  33. data/spec/fixtures/single-feed-2.atom +32 -0
  34. data/spec/fixtures/single-feed.atom +24 -0
  35. data/spec/spec_helper.rb +43 -0
  36. metadata +254 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTM0N2U0ZmU0YzkwMThiMzFlYTc4MGUyYzZhNmQwOWFjNTVhZTBhYQ==
5
+ data.tar.gz: !binary |-
6
+ ZWMzM2MyNTM3ZWUzMDI4NmU5YzcwMTY1Yzc0N2EwNjQwNjhjYTU1Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzY0MGU4MzQ1ZDA0NmRkZjA1ZWI5Y2M3YWZlMDVlNWE0NWZiY2U3OTRjNmRm
10
+ ZTlkODA0YjQ1NTBjNDg0Mjg1MDgyOTM4N2Y2OTI4NzdmNjIyNjFlMTcwNDlh
11
+ YjlkMTJlNzkyMGM0ZGU1YWU5MWY3NDYzZTY0ODI4Njg4NWQ1NDU=
12
+ data.tar.gz: !binary |-
13
+ MGY0ZjYwNTliNzM3YWEyOTU5MzNjOGY3ZTViMDE5MDcyNTY0NTg3NGE0MWMz
14
+ YjBmNzdmN2U5YzgwYWNkMTFhMWNlNzg0YmVkZWRjMzk2ZDU1MjJlNGVjODYx
15
+ MjliYTJlNzg0ODc2YjU2MzEzNTdmNzVlYWUyMGQ5ZTZmYjkwMjI=
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .bundle/install.log
2
+ coverage
3
+ .env
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ rvm:
5
+ - 2.3.1
6
+ env:
7
+ global:
8
+ - BASE_URI='http://open-data-certificate.dev'
9
+ - secure: w1kS3tl+NK92wmvzdgLelfL8JI1CXyFunVJUJHwpN/evGDGrLxxXiCHP5tLYh/LQ1LuuzHLjLSwUHovRpDVFwS6eP0OOxDxKECIAWb5H2TORKl+70G4H3JRTkOwh9LhbpE6X/3d9za+uSujtXhuYRLZ4cifEigbHfclOqywr92s=
10
+ - secure: mIPq3Xf91/IC2t2s3uGo1hVXu/nwjVia9cKtA00Kfhxkrp8M3hBzpFtGKuhj5HARkGozpEkBS0jPU3MK93pGHCY8PzhuUAXd0Cpaek59CGfcRNf2TD95z0SrL+HoD9kagvAV9M10L9x5hqEv/lKCHh2S8qxrUbvy9TIdrZyz9aE=
11
+ - secure: T89jTDvzYTgBwJjwjc+Wk1+Mhbh9Orz35LaPCcw3zZ9GIpnYS6FLnMBSf9UrZAYR7ZHJf8vpoPtcVnEBPIORtMImPPJ7TBxIK3pEwzrBMnUBWkP+3BCvJRESFn1mkSePhpTNLjrLYXx8GL+t4yoZKqPuzGWM9rTltbTOzgeD1Hg=
12
+ deploy:
13
+ provider: rubygems
14
+ api_key:
15
+ secure: y8U533/c1vC7oKISdh/C2MVU1nTVq6u85Pz2TaGyIdsOkXaOeMeRMSsyoZkNxY1dO/qMRb790YpSZbHSaAq/y7+v6Z42AFn64R0krRjfA5y/+3hqEIr+Kf5UUk/Q29KHerWVxHMvboMpKP30PwaFtE7MUEUqscqfTUFQFi6TutA=
16
+ gem: certificate-factory
17
+ on:
18
+ tags: true
19
+ repo: theodi/certificate-factory
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ultron.gemspec
4
+ gemspec
5
+
6
+ gem 'henry'
data/Gemfile.lock ADDED
@@ -0,0 +1,154 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ certificate-factory (0.1.0)
5
+ dotenv
6
+ httparty
7
+ rake
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.4.0)
13
+ backports (3.6.8)
14
+ coderay (1.1.1)
15
+ colorize (0.7.7)
16
+ coveralls (0.8.14)
17
+ json (>= 1.8, < 3)
18
+ simplecov (~> 0.12.0)
19
+ term-ansicolor (~> 1.3)
20
+ thor (~> 0.19.1)
21
+ tins (~> 1.6.0)
22
+ crack (0.4.3)
23
+ safe_yaml (~> 1.0.0)
24
+ descendants_tracker (0.0.4)
25
+ thread_safe (~> 0.3, >= 0.3.1)
26
+ diff-lcs (1.2.5)
27
+ docile (1.1.5)
28
+ dotenv (2.1.1)
29
+ ethon (0.9.0)
30
+ ffi (>= 1.3.0)
31
+ faraday (0.9.2)
32
+ multipart-post (>= 1.2, < 3)
33
+ faraday_middleware (0.10.0)
34
+ faraday (>= 0.7.4, < 0.10)
35
+ ffi (1.9.13)
36
+ gh (0.14.0)
37
+ addressable
38
+ backports
39
+ faraday (~> 0.8)
40
+ multi_json (~> 1.0)
41
+ net-http-persistent (>= 2.7)
42
+ net-http-pipeline
43
+ git (1.3.0)
44
+ github_api (0.14.0)
45
+ addressable (~> 2.4.0)
46
+ descendants_tracker (~> 0.0.4)
47
+ faraday (~> 0.8, < 0.10)
48
+ hashie (>= 3.4)
49
+ oauth2
50
+ github_changelog_generator (1.9.0)
51
+ colorize (~> 0.7)
52
+ github_api (~> 0.12)
53
+ hashdiff (0.3.0)
54
+ hashie (3.4.4)
55
+ henry (0.1.3)
56
+ git (~> 1.3)
57
+ github_api (~> 0.13)
58
+ github_changelog_generator (= 1.9.0)
59
+ thor (~> 0.19.1)
60
+ travis (~> 1.8.2)
61
+ highline (1.7.8)
62
+ httparty (0.13.7)
63
+ json (~> 1.8)
64
+ multi_xml (>= 0.5.2)
65
+ json (1.8.3)
66
+ jwt (1.5.1)
67
+ launchy (2.4.3)
68
+ addressable (~> 2.3)
69
+ method_source (0.8.2)
70
+ multi_json (1.12.1)
71
+ multi_xml (0.5.5)
72
+ multipart-post (2.0.0)
73
+ net-http-persistent (2.9.4)
74
+ net-http-pipeline (1.0.1)
75
+ oauth2 (1.1.0)
76
+ faraday (>= 0.8, < 0.10)
77
+ jwt (~> 1.0, < 1.5.2)
78
+ multi_json (~> 1.3)
79
+ multi_xml (~> 0.5)
80
+ rack (>= 1.2, < 3)
81
+ pry (0.10.4)
82
+ coderay (~> 1.1.0)
83
+ method_source (~> 0.8.1)
84
+ slop (~> 3.4)
85
+ pry-remote (0.1.8)
86
+ pry (~> 0.9)
87
+ slop (~> 3.0)
88
+ pusher-client (0.6.2)
89
+ json
90
+ websocket (~> 1.0)
91
+ rack (2.0.1)
92
+ rake (11.2.2)
93
+ rspec (3.5.0)
94
+ rspec-core (~> 3.5.0)
95
+ rspec-expectations (~> 3.5.0)
96
+ rspec-mocks (~> 3.5.0)
97
+ rspec-core (3.5.1)
98
+ rspec-support (~> 3.5.0)
99
+ rspec-expectations (3.5.0)
100
+ diff-lcs (>= 1.2.0, < 2.0)
101
+ rspec-support (~> 3.5.0)
102
+ rspec-mocks (3.5.0)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.5.0)
105
+ rspec-support (3.5.0)
106
+ safe_yaml (1.0.4)
107
+ simplecov (0.12.0)
108
+ docile (~> 1.1.0)
109
+ json (>= 1.8, < 3)
110
+ simplecov-html (~> 0.10.0)
111
+ simplecov-html (0.10.0)
112
+ simplecov-rcov (0.2.3)
113
+ simplecov (>= 0.4.1)
114
+ slop (3.6.0)
115
+ term-ansicolor (1.3.2)
116
+ tins (~> 1.0)
117
+ thor (0.19.1)
118
+ thread_safe (0.3.5)
119
+ tins (1.6.0)
120
+ travis (1.8.2)
121
+ backports
122
+ faraday (~> 0.9)
123
+ faraday_middleware (~> 0.9, >= 0.9.1)
124
+ gh (~> 0.13)
125
+ highline (~> 1.6)
126
+ launchy (~> 2.1)
127
+ pusher-client (~> 0.4)
128
+ typhoeus (~> 0.6, >= 0.6.8)
129
+ typhoeus (0.8.0)
130
+ ethon (>= 0.8.0)
131
+ vcr (3.0.3)
132
+ webmock (1.24.6)
133
+ addressable (>= 2.3.6)
134
+ crack (>= 0.3.2)
135
+ hashdiff
136
+ websocket (1.2.3)
137
+
138
+ PLATFORMS
139
+ ruby
140
+
141
+ DEPENDENCIES
142
+ certificate-factory!
143
+ coveralls
144
+ henry
145
+ pry
146
+ pry-remote
147
+ rspec
148
+ simplecov
149
+ simplecov-rcov
150
+ vcr
151
+ webmock
152
+
153
+ BUNDLED WITH
154
+ 1.12.5
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+ ---------------------
3
+
4
+ Copyright (c) 2014 The Open Data Institute
5
+
6
+ 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:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ 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.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ [![Build Status](http://img.shields.io/travis/theodi/certificate-factory.svg?style=flat-square)](https://travis-ci.org/theodi/certificate-factory)
2
+ [![Dependency CI](http://dependencyci.com/github/theodi/certificate-factory/badge?style=flat-square)](http://dependencyci.com/github/theodi/certificate-factory)
3
+ [![Coverage Status](http://img.shields.io/coveralls/theodi/certificate-factory.svg?style=flat-square)](https://coveralls.io/r/theodi/certificate-factory)
4
+ [![Code Climate](http://img.shields.io/codeclimate/github/theodi/certificate-factory.svg?style=flat-square)](https://codeclimate.com/github/theodi/certificate-factory)
5
+ [![Gem Version](http://img.shields.io/gem/v/certificate-factory.svg?style=flat-square)](https://rubygems.org/gems/certificate-factory)
6
+ [![License](http://img.shields.io/:license-mit-blue.svg?style=flat-square)](http://theodi.mit-license.org)
7
+
8
+ # Certificate Factory
9
+
10
+ Automagically generate [Open Data Certificates](https://certificates.theodi.org/)
11
+ from a CKAN Dataset or Data.gov.uk atom feed.
12
+
13
+ # Getting started
14
+
15
+ ## Clone the repo
16
+
17
+ git clone git@github.com:theodi/certificate-generator.git
18
+
19
+ ## Add some environment variables
20
+
21
+ * Create a file named `.env`
22
+ * Add the following you your newly-created file:
23
+
24
+ BASE_URI='https://certificates.theodi.org/'
25
+ ODC_USERNAME='{YOUR OPEN DATA CERTIFICATE USERNAME}'
26
+ ODC_API_KEY='{YOUR OPEN DATA CERTIFICATE API KEY}'
27
+
28
+ You can get your API key from your Account page when logged into the Open Data Certificates website
29
+
30
+ If you are running your own instance of Open Data Certificates (such as on your own machine), simply replace the `BASE_URL` with the URL of the instance you want to generate certificates on.
31
+
32
+ ## Run some commands!
33
+
34
+ To generate a single certificate from a CKAN dataset, run the following:
35
+
36
+ rake generate:certificate URL="{CKAN dataset URL}"
37
+
38
+ To generate multiple certificates as part of a campaign run the following:
39
+
40
+ rake generate:certificates CAMPAIGN=name URL="http://data.gov.uk/feeds/custom.atom"
41
+
42
+ This will iterate through the feed and queue up all datasets in the feed by default, if you want to limit it specify a `LIMIT` parameter like so:
43
+
44
+ rake generate:certificates CAMPAIGN=name URL="http://data.gov.uk/feeds/custom.atom" LIMIT=2
45
+
46
+ By default it will store the links to result urls in `CAMPAIGN.csv` you can change this by specifying an `OUTPUT` parameter in case you want a descriptive campaign name but a simpler result outputfile:
47
+
48
+ rake generate:certificates OUTPUT=output.csv CAMPAIGN=name URL="http://data.gov.uk/feeds/custom.atom" LIMIT=2
49
+
50
+ If you want to collect the results of the campaign run in a csv file then you can run:
51
+
52
+ rake generate:results FILE=output.csv RESULTS=results.csv
53
+
54
+ Specifying the output of the `generate` task as `FILE`. This will collect the results of the import, waiting for each job to finish.
data/Rakefile ADDED
@@ -0,0 +1,114 @@
1
+ $:.unshift File.join( File.dirname(__FILE__), "lib")
2
+
3
+ require 'rspec/core/rake_task'
4
+ require 'logger'
5
+ require 'csv'
6
+ require 'httparty'
7
+ require 'certificate-factory'
8
+
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
11
+ task :default => :spec
12
+
13
+ logger = Logger.new(STDOUT)
14
+ logger.level = Logger::DEBUG
15
+ logger.formatter = proc {|level, datetime, _, msg| msg + "\n"}
16
+
17
+ namespace :generate do
18
+
19
+ task :certificate do
20
+ if ENV['URL']
21
+ cert = CertificateFactory::Certificate.new(ENV['URL'])
22
+ gen = cert.generate
23
+ if gen[:success] == "pending"
24
+ logger.info "pending: #{gen[:dataset_url]}"
25
+ result = cert.result
26
+
27
+ logger.info "published: #{result[:published]}"
28
+ if result[:success]
29
+ logger.info "user: #{result[:user]}"
30
+ logger.info "certificate_url: #{result[:certificate_url]}"
31
+ end
32
+ else
33
+ logger.error "#{gen[:error]} #{gen[:documentation_url]}"
34
+ puts gen.inspect
35
+ end
36
+ else
37
+ logger.error "Please specify a URL to generate a certificate for"
38
+ end
39
+ end
40
+
41
+ task :certificates do
42
+ url = ENV['URL']
43
+ file = ENV['FILE']
44
+ if (url || file) && (campaign = ENV['CAMPAIGN'])
45
+ #dated_campaign = [campaign, DateTime.now.iso8601].join('-')
46
+ # Create factory
47
+ output = ENV.fetch("OUTPUT", "#{campaign}.csv")
48
+ limit = ENV['LIMIT'].to_i if ENV['LIMIT']
49
+ if url
50
+ factory = CertificateFactory::Factory.new(feed: url, limit: limit, campaign: campaign, logger: logger)
51
+ elsif file
52
+ factory = CertificateFactory::CSVFactory.new(file: file, limit: limit, campaign: campaign, logger: logger)
53
+ end
54
+ count = 0
55
+ CSV.open(output, "w") do |csv|
56
+ csv << ["documentation_url", "dataset_url"]
57
+ factory.build do |r|
58
+ csv << r.values_at(:documentation_url, :dataset_url)
59
+ logger.info "#{r[:success]}: #{r[:documentation_url]}"
60
+ count += 1
61
+ end
62
+ end
63
+ logger.info "#{count} certificates queued. See #{output} for results"
64
+ else
65
+ logger.error "Please specify a URL for a feed and a CAMPAIGN to generate certificates for"
66
+ end
67
+ end
68
+
69
+ task :results do
70
+ if path = ENV['FILE']
71
+ if output = ENV['RESULTS']
72
+ CSV.open(output, 'w') do |csv|
73
+ csv << ["Success?", "Published?", "Documenation URL", "Certificate URL", "User"]
74
+ CSV.foreach(path, :headers => :first_row) do |c|
75
+ if dataset_url = c["dataset_url"]
76
+ puts dataset_url
77
+ result = CertificateFactory::Certificate.new(c['documentation_url'], :dataset_url => dataset_url).result
78
+ csv << result.values_at(:success, :published, :documentation_url, :certificate_url, :user)
79
+ end
80
+ end
81
+ end
82
+ else
83
+ logger.error "Please specify a RESULTS path"
84
+ end
85
+ else
86
+ logger.error "Please specify a FILE to check for results from"
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ namespace :update do
93
+ task :certificate do
94
+ if ENV['URL']
95
+ cert = CertificateFactory::Certificate.new(ENV['URL'])
96
+ gen = cert.update
97
+ if gen[:success] == "pending" || gen[:success] == true
98
+ puts gen.inspect
99
+ result = cert.result
100
+
101
+ if result[:published]
102
+ logger.info "published"
103
+ end
104
+ logger.info "user: #{result[:user]}"
105
+ logger.info "certificate_url: #{result[:certificate_url]}"
106
+ else
107
+ logger.error "#{gen[:error]} #{gen[:documentation_url]}"
108
+ puts gen.inspect
109
+ end
110
+ else
111
+ logger.error "Please specify a URL to generate a certificate for"
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,33 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your gem's version:
4
+ require "certificate-factory/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "certificate-factory"
9
+ s.version = CertificateFactory::VERSION
10
+ s.authors = ["Stuart Harrison"]
11
+ s.email = ["tech@theodi.org"]
12
+ s.homepage = "http://theodi.org"
13
+ s.summary = "Automagically generate Open Data Certificates from a CKAN Dataset or Data.gov.uk atom feed."
14
+ s.description = "Automagically generate Open Data Certificates from a CKAN Dataset or Data.gov.uk atom feed."
15
+ s.license = "MIT"
16
+
17
+ s.files = `git ls-files`.split($\)
18
+ s.require_paths = ["lib", "app"]
19
+ s.test_files = Dir["spec/**/*"]
20
+
21
+ s.add_dependency "httparty"
22
+ s.add_dependency "dotenv"
23
+ s.add_dependency "rake"
24
+
25
+ s.add_development_dependency "rspec"
26
+ s.add_development_dependency "simplecov"
27
+ s.add_development_dependency "simplecov-rcov"
28
+ s.add_development_dependency "coveralls"
29
+ s.add_development_dependency "pry"
30
+ s.add_development_dependency "webmock"
31
+ s.add_development_dependency "vcr"
32
+ s.add_development_dependency "pry-remote"
33
+ end
data/env.example ADDED
@@ -0,0 +1,3 @@
1
+ BASE_URI='http://open-data-certificate.dev'
2
+ ODC_USERNAME=''
3
+ ODC_API_KEY=''
@@ -0,0 +1,14 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'httparty'
4
+ require 'dotenv'
5
+
6
+ Dotenv.load
7
+
8
+ require 'certificate-factory/api'
9
+ require 'certificate-factory/certificate'
10
+ require 'certificate-factory/factory'
11
+
12
+ module CertificateFactory
13
+
14
+ end