middleman-leanpub 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 +7 -0
- data/.gitignore +5 -0
- data/Gemfile +19 -0
- data/Rakefile +14 -0
- data/features/support/env.rb +4 -0
- data/lib/middleman-leanpub.rb +39 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-leanpub.gemspec +26 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 76c54d7191aaa64947c573b82ff20f3b8b4de740
|
4
|
+
data.tar.gz: 68ea53b2416b4517b93ec6dd93c20c3041bedbe2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 225acbb3b46659fbc855f85c8b24fed4b46b6c5fd16b231431af90363d43bb4863e9e752bd264e10a79a2b3347f75f54ce598656c3a0da0d0e53d8062c284f6a
|
7
|
+
data.tar.gz: 83c03121a9f3ef169ed7d09c34eb24ffed7b93910d34ddc32fd6894cc0f463380ff286d19600fa632ab6a140806e493881f726f111307f93670b55226446b461
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# If you do not have OpenSSL installed, update
|
2
|
+
# the following line to use "http://" instead
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in middleman-leanpub.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rdoc'
|
11
|
+
gem 'yard'
|
12
|
+
end
|
13
|
+
|
14
|
+
group :test do
|
15
|
+
gem 'cucumber'
|
16
|
+
gem 'fivemat'
|
17
|
+
gem 'aruba'
|
18
|
+
gem 'rspec'
|
19
|
+
end
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/clean'
|
11
|
+
|
12
|
+
task test: ['cucumber']
|
13
|
+
|
14
|
+
task default: :test
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "middleman-core"
|
2
|
+
require "json"
|
3
|
+
require "net/http"
|
4
|
+
require "uri"
|
5
|
+
|
6
|
+
class LeanpubExtension < ::Middleman::Extension
|
7
|
+
option :api_key, nil, 'LeanPub API Key to get private data'
|
8
|
+
option :book, nil, 'Book to download data for'
|
9
|
+
|
10
|
+
class HttpError < StandardError; end
|
11
|
+
|
12
|
+
def initialize(app, options_hash={}, &block)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def after_configuration
|
17
|
+
uri = URI.parse("https://leanpub.com/#{options.book}.json?api_key=#{options.api_key}")
|
18
|
+
|
19
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
20
|
+
http.use_ssl = true
|
21
|
+
|
22
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
23
|
+
response = http.request(request)
|
24
|
+
|
25
|
+
raise HttpError, response.body unless response.code.to_i == 200
|
26
|
+
|
27
|
+
# Gimme dat JSON
|
28
|
+
result = JSON.parse(response.body)
|
29
|
+
|
30
|
+
filepath = File.join(app.root_path, app.config.data_dir, 'leanpub.yml')
|
31
|
+
file = File.open(filepath, 'w') do |f|
|
32
|
+
f.write("reader_count: #{result['total_copies_sold'].to_i}")
|
33
|
+
end
|
34
|
+
rescue HttpError
|
35
|
+
puts "Shit did not go well with LeanPub"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
::Middleman::Extensions.register(:leanpub, LeanpubExtension)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'middleman-leanpub'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "middleman-leanpub"
|
6
|
+
s.version = "0.0.1"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Phil Sturgeon"]
|
9
|
+
s.email = ["me@philsturgeon.uk"]
|
10
|
+
s.homepage = "https://github.com/philsturgeon/middleman-leanpub"
|
11
|
+
s.summary = %q{Grab data for LeanPub Books}
|
12
|
+
s.description = %q{Use the LeanPub API to download data for a book, then store it in
|
13
|
+
data files for access in your templates}
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# The version of middleman-core your extension depends on
|
22
|
+
s.add_runtime_dependency 'middleman-core', '~> 3.3', '>= 3.3.10'
|
23
|
+
|
24
|
+
# Additional dependencies
|
25
|
+
# s.add_runtime_dependency("gem-name", "gem-version")
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-leanpub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phil Sturgeon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.3.10
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.3.10
|
33
|
+
description: |-
|
34
|
+
Use the LeanPub API to download data for a book, then store it in
|
35
|
+
data files for access in your templates
|
36
|
+
email:
|
37
|
+
- me@philsturgeon.uk
|
38
|
+
executables: []
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- ".gitignore"
|
43
|
+
- Gemfile
|
44
|
+
- Rakefile
|
45
|
+
- features/support/env.rb
|
46
|
+
- lib/middleman-leanpub.rb
|
47
|
+
- lib/middleman_extension.rb
|
48
|
+
- middleman-leanpub.gemspec
|
49
|
+
homepage: https://github.com/philsturgeon/middleman-leanpub
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.2.2
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: Grab data for LeanPub Books
|
73
|
+
test_files:
|
74
|
+
- features/support/env.rb
|
75
|
+
has_rdoc:
|