leanpub_api 0.0.3 → 0.0.4
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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +23 -4
- data/leanpub_api.gemspec +6 -6
- data/lib/leanpub_api/base.rb +25 -0
- data/lib/leanpub_api/book_summary.rb +1 -21
- data/lib/leanpub_api/sales_summary.rb +9 -0
- data/lib/leanpub_api/version.rb +1 -1
- data/spec/fixtures/leanpub_cassettes/sales_summary.yml +57 -0
- data/spec/lib/leanpub_api/base_spec.rb +13 -0
- data/spec/lib/leanpub_api/book_summary_spec.rb +0 -10
- data/spec/lib/leanpub_api/sales_summary_spec.rb +66 -0
- metadata +41 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4db60a908c6f155cc67f120aa35fdac2dbdd7736
|
4
|
+
data.tar.gz: a300c1be11843a68a5501a26e85a7b3287d5b983
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4680adc4fbf7edddc3d09475e36588920475df53b55a45986cf805f4c4f508f1fe5da2cf469f31d3db0aa5f54750128a7a90263aa4fd79adcbae277914bb3fd5
|
7
|
+
data.tar.gz: dae321d7683841af5c90149bb6036da0ace3d70b0dfb90e479ed71630d6e644bd80f5844bbcae0466e5a4c91bdd9f199fad3c0219e6a8aaf536d5337ec577d33
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Leanpub API wrapper for Ruby
|
2
2
|
|
3
|
-
A simple Ruby wrapper for the [Leanpub API](https://leanpub.com/help/api). Currently supports the API's book summary functions, with aspirations to do
|
3
|
+
A simple Ruby wrapper for the [Leanpub API](https://leanpub.com/help/api). Currently supports the API's book and sales summary functions, with aspirations to do
|
4
4
|
more.
|
5
5
|
|
6
6
|
**Disclaimer:** Leanpub is a service of Ruboss Technology Corporation, a
|
@@ -35,7 +35,7 @@ by [accessing your Leanpub account](https://leanpub.com/dashboard).
|
|
35
35
|
The gem currently supports the Leanpub API's book summary functions.
|
36
36
|
|
37
37
|
```ruby
|
38
|
-
require '
|
38
|
+
require 'leanpub_api'
|
39
39
|
|
40
40
|
book = LeanpubAPI::BookSummary.new('<book-slug>', '<api-key>')
|
41
41
|
|
@@ -52,6 +52,26 @@ puts book.total_revenue
|
|
52
52
|
puts book.possible_reader_count
|
53
53
|
```
|
54
54
|
|
55
|
+
You can also get the sales summary for a Leanpub book.
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
require 'leanpub_api'
|
59
|
+
|
60
|
+
sales = LeanpubAPI::SalesSummary.new('<book-slug>', '<api-key>')
|
61
|
+
|
62
|
+
puts sales.book
|
63
|
+
puts sales.url
|
64
|
+
puts sales.total_author_royalties
|
65
|
+
puts sales.total_book_royalties
|
66
|
+
puts sales.num_happy_readers
|
67
|
+
puts sales.num_happy_paid_purchases
|
68
|
+
puts sales.num_refunded_purchases
|
69
|
+
puts sales.unpaid_royalties
|
70
|
+
puts sales.royalties_currently_due
|
71
|
+
puts sales.royalties_due_on_first_of_next_month
|
72
|
+
puts sales.paid_royalties
|
73
|
+
```
|
74
|
+
|
55
75
|
## Development
|
56
76
|
|
57
77
|
Tests expect a `.env` file at the project's root, with the following
|
@@ -64,14 +84,13 @@ environment variables:
|
|
64
84
|
|
65
85
|
Add wrappers for other API functionality:
|
66
86
|
|
67
|
-
- Sales summary
|
68
87
|
- All sales data
|
69
88
|
- Preview functions
|
70
89
|
- Publish functions
|
71
90
|
- Preview/publish job status
|
72
91
|
- Coupon management
|
73
92
|
|
74
|
-
|
93
|
+
Test against other Rubies
|
75
94
|
|
76
95
|
## Contributing
|
77
96
|
|
data/leanpub_api.gemspec
CHANGED
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_runtime_dependency "httparty",
|
21
|
+
spec.add_runtime_dependency "httparty", '~> 0.12.0', '>= 0.12.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler",
|
24
|
-
spec.add_development_dependency "rake",
|
25
|
-
spec.add_development_dependency "webmock",
|
26
|
-
spec.add_development_dependency "vcr",
|
27
|
-
spec.add_development_dependency "dotenv",
|
23
|
+
spec.add_development_dependency "bundler", '~> 1.3'
|
24
|
+
spec.add_development_dependency "rake", '~> 10.1', '>= 10.1.1'
|
25
|
+
spec.add_development_dependency "webmock", '~> 1.14', '>= 1.14.0'
|
26
|
+
spec.add_development_dependency "vcr", '~> 2.6', '>= 2.6.0'
|
27
|
+
spec.add_development_dependency "dotenv", '~> 0.9', '>= 0.9.0'
|
28
28
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module LeanpubAPI
|
2
|
+
class Base
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'https://leanpub.com'
|
5
|
+
|
6
|
+
def initialize(book_slug, api_key)
|
7
|
+
@book_slug = book_slug
|
8
|
+
@api_key = api_key
|
9
|
+
end
|
10
|
+
|
11
|
+
def info(force = false)
|
12
|
+
force ? @info = get_info : @info ||= get_info
|
13
|
+
end
|
14
|
+
|
15
|
+
def method_missing(name, *args, &block)
|
16
|
+
info.has_key?(name.to_s) ? info[name.to_s] : super
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_info
|
22
|
+
self.class.get(path)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,27 +1,7 @@
|
|
1
1
|
module LeanpubAPI
|
2
|
-
class BookSummary
|
3
|
-
include HTTParty
|
4
|
-
base_uri 'https://leanpub.com'
|
5
|
-
|
6
|
-
def initialize(book_slug, api_key)
|
7
|
-
@book_slug = book_slug
|
8
|
-
@api_key = api_key
|
9
|
-
end
|
10
|
-
|
11
|
-
def info(force = false)
|
12
|
-
force ? @info = get_info : @info ||= get_info
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing(name, *args, &block)
|
16
|
-
info.has_key?(name.to_s) ? info[name.to_s] : super
|
17
|
-
end
|
18
|
-
|
2
|
+
class BookSummary < LeanpubAPI::Base
|
19
3
|
private
|
20
4
|
|
21
|
-
def get_info
|
22
|
-
self.class.get(path)
|
23
|
-
end
|
24
|
-
|
25
5
|
def path
|
26
6
|
"/#{@book_slug}.json?api_key=#{@api_key}"
|
27
7
|
end
|
data/lib/leanpub_api/version.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://leanpub.com/<LEANPUB_BOOK_SLUG>/sales.json?api_key=<LEANPUB_API_KEY>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers: {}
|
10
|
+
response:
|
11
|
+
status:
|
12
|
+
code: 200
|
13
|
+
message: OK
|
14
|
+
headers:
|
15
|
+
Cache-Control:
|
16
|
+
- max-age=0, private, must-revalidate
|
17
|
+
- no-cache="set-cookie"
|
18
|
+
Content-Type:
|
19
|
+
- application/json; charset=utf-8
|
20
|
+
Date:
|
21
|
+
- Mon, 17 Feb 2014 01:12:04 GMT
|
22
|
+
Etag:
|
23
|
+
- '"64209636cfbe12942dd4c85877804afa"'
|
24
|
+
Server:
|
25
|
+
- nginx + Phusion Passenger 4.0.29
|
26
|
+
Set-Cookie:
|
27
|
+
- AWSELB=BF7915350C754439EF4952CB0CB801868D298314801C9FE6ECB1E0A62F0A1CC471D3F7B3BCEF808A2A657B84781E305B69B23522CD91D8473382F22DEB898C2514173621FE;PATH=/
|
28
|
+
- cookied-flash=%7B%7D; path=/; secure
|
29
|
+
- domain-info=%7B%22root%22%3A%22https%3A%2F%2Fleanpub.com%2F%22%7D; path=/;
|
30
|
+
expires=Tue, 18-Feb-2014 01:12:04 GMT; secure
|
31
|
+
- remember_token=d1248d8ebf3303d1f74c2788df68b618f841c5e2; path=/; expires=Tue,
|
32
|
+
17-Feb-2015 01:12:04 GMT; secure
|
33
|
+
- user-info=; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT; secure
|
34
|
+
Status:
|
35
|
+
- 200 OK
|
36
|
+
Strict-Transport-Security:
|
37
|
+
- max-age=31536000
|
38
|
+
X-Powered-By:
|
39
|
+
- Phusion Passenger 4.0.29
|
40
|
+
X-Rack-Cache:
|
41
|
+
- miss
|
42
|
+
X-Request-Id:
|
43
|
+
- 84ff9ce7201fc68fd7125e2d5b96753b
|
44
|
+
X-Runtime:
|
45
|
+
- '0.126614'
|
46
|
+
X-Ua-Compatible:
|
47
|
+
- IE=Edge,chrome=1
|
48
|
+
Transfer-Encoding:
|
49
|
+
- chunked
|
50
|
+
Connection:
|
51
|
+
- keep-alive
|
52
|
+
body:
|
53
|
+
encoding: UTF-8
|
54
|
+
string: '{"book":"<LEANPUB_BOOK_SLUG>","url":"https://leanpub.com/<LEANPUB_BOOK_SLUG>","total_author_royalties":"23456.78","total_book_royalties":"3456.78","num_happy_readers":3534,"num_happy_paid_purchases":3522,"num_refunded_purchases":12,"unpaid_royalties":"1208.75","royalties_currently_due":"0.0","royalties_due_on_first_of_next_month":"1208.75","paid_royalties":"12345.67"}'
|
55
|
+
http_version:
|
56
|
+
recorded_at: Mon, 17 Feb 2014 01:12:25 GMT
|
57
|
+
recorded_with: VCR 2.6.0
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe LeanpubAPI::Base do
|
4
|
+
describe "default attributes" do
|
5
|
+
it "include HTTParty methods" do
|
6
|
+
LeanpubAPI::BookSummary.must_include HTTParty
|
7
|
+
end
|
8
|
+
|
9
|
+
it "have the base URL set to the Leanpub API endpoint" do
|
10
|
+
LeanpubAPI::BookSummary.base_uri.must_equal 'https://leanpub.com'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,16 +1,6 @@
|
|
1
1
|
require_relative '../../spec_helper'
|
2
2
|
|
3
3
|
describe LeanpubAPI::BookSummary do
|
4
|
-
describe "default attributes" do
|
5
|
-
it "include HTTParty methods" do
|
6
|
-
LeanpubAPI::BookSummary.must_include HTTParty
|
7
|
-
end
|
8
|
-
|
9
|
-
it "have the base URL set to the Leanpub API endpoint" do
|
10
|
-
LeanpubAPI::BookSummary.base_uri.must_equal 'https://leanpub.com'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
4
|
describe "GET book info" do
|
15
5
|
let(:summary) { LeanpubAPI::BookSummary.new(book_slug, api_key) }
|
16
6
|
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative '../../spec_helper'
|
2
|
+
|
3
|
+
describe LeanpubAPI::SalesSummary do
|
4
|
+
describe "GET sales summary info" do
|
5
|
+
let(:summary) { LeanpubAPI::SalesSummary.new(book_slug, api_key) }
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
VCR.insert_cassette 'sales_summary', record: :new_episodes
|
9
|
+
end
|
10
|
+
|
11
|
+
after :each do
|
12
|
+
VCR.eject_cassette
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has data" do
|
16
|
+
summary.must_respond_to :info
|
17
|
+
end
|
18
|
+
|
19
|
+
it "parses the JSON response to a hash" do
|
20
|
+
summary.info.must_be_instance_of Hash
|
21
|
+
end
|
22
|
+
|
23
|
+
it "performs the request and gets the data" do
|
24
|
+
summary.info["book"].must_equal "everydayrailsrspec"
|
25
|
+
summary.info["url"].must_equal "https://leanpub.com/everydayrailsrspec"
|
26
|
+
summary.info["total_author_royalties"].must_equal "23456.78"
|
27
|
+
summary.info["total_book_royalties"].must_equal "3456.78"
|
28
|
+
summary.info["num_happy_readers"].must_equal 3534
|
29
|
+
summary.info["num_happy_paid_purchases"].must_equal 3522
|
30
|
+
summary.info["num_refunded_purchases"].must_equal 12
|
31
|
+
summary.info["unpaid_royalties"].must_equal "1208.75"
|
32
|
+
summary.info["royalties_currently_due"].must_equal "0.0"
|
33
|
+
summary.info["royalties_due_on_first_of_next_month"].must_equal "1208.75"
|
34
|
+
summary.info["paid_royalties"].must_equal "12345.67"
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "dynamic attributes" do
|
38
|
+
before do
|
39
|
+
summary.info
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns an attribute if present in the info" do
|
43
|
+
summary.num_happy_readers.must_equal 3534
|
44
|
+
end
|
45
|
+
|
46
|
+
it "raises method missing if an attribute is not present in the info" do
|
47
|
+
lambda { summary.bad_attribute }.must_raise NoMethodError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "caching" do
|
52
|
+
before do
|
53
|
+
summary.info
|
54
|
+
stub_request(:any, /leanpub.com/).to_timeout
|
55
|
+
end
|
56
|
+
|
57
|
+
it "caches the info" do
|
58
|
+
summary.info.must_be_instance_of Hash
|
59
|
+
end
|
60
|
+
|
61
|
+
it "refreshes the info if forced" do
|
62
|
+
lambda { summary.info(true) }.must_raise Timeout::Error
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leanpub_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Sumner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -17,6 +17,9 @@ dependencies:
|
|
17
17
|
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.12.0
|
20
|
+
- - '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.12.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -24,6 +27,9 @@ dependencies:
|
|
24
27
|
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: 0.12.0
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.12.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: bundler
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -43,6 +49,9 @@ dependencies:
|
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.1'
|
54
|
+
- - '>='
|
46
55
|
- !ruby/object:Gem::Version
|
47
56
|
version: 10.1.1
|
48
57
|
type: :development
|
@@ -50,6 +59,9 @@ dependencies:
|
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
51
60
|
requirements:
|
52
61
|
- - ~>
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '10.1'
|
64
|
+
- - '>='
|
53
65
|
- !ruby/object:Gem::Version
|
54
66
|
version: 10.1.1
|
55
67
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +69,9 @@ dependencies:
|
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
58
70
|
requirements:
|
59
71
|
- - ~>
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '1.14'
|
74
|
+
- - '>='
|
60
75
|
- !ruby/object:Gem::Version
|
61
76
|
version: 1.14.0
|
62
77
|
type: :development
|
@@ -64,6 +79,9 @@ dependencies:
|
|
64
79
|
version_requirements: !ruby/object:Gem::Requirement
|
65
80
|
requirements:
|
66
81
|
- - ~>
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '1.14'
|
84
|
+
- - '>='
|
67
85
|
- !ruby/object:Gem::Version
|
68
86
|
version: 1.14.0
|
69
87
|
- !ruby/object:Gem::Dependency
|
@@ -71,6 +89,9 @@ dependencies:
|
|
71
89
|
requirement: !ruby/object:Gem::Requirement
|
72
90
|
requirements:
|
73
91
|
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '2.6'
|
94
|
+
- - '>='
|
74
95
|
- !ruby/object:Gem::Version
|
75
96
|
version: 2.6.0
|
76
97
|
type: :development
|
@@ -78,6 +99,9 @@ dependencies:
|
|
78
99
|
version_requirements: !ruby/object:Gem::Requirement
|
79
100
|
requirements:
|
80
101
|
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.6'
|
104
|
+
- - '>='
|
81
105
|
- !ruby/object:Gem::Version
|
82
106
|
version: 2.6.0
|
83
107
|
- !ruby/object:Gem::Dependency
|
@@ -85,6 +109,9 @@ dependencies:
|
|
85
109
|
requirement: !ruby/object:Gem::Requirement
|
86
110
|
requirements:
|
87
111
|
- - ~>
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0.9'
|
114
|
+
- - '>='
|
88
115
|
- !ruby/object:Gem::Version
|
89
116
|
version: 0.9.0
|
90
117
|
type: :development
|
@@ -92,6 +119,9 @@ dependencies:
|
|
92
119
|
version_requirements: !ruby/object:Gem::Requirement
|
93
120
|
requirements:
|
94
121
|
- - ~>
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0.9'
|
124
|
+
- - '>='
|
95
125
|
- !ruby/object:Gem::Version
|
96
126
|
version: 0.9.0
|
97
127
|
description: A simple Ruby wrapper for the Leanpub API.
|
@@ -102,16 +132,22 @@ extensions: []
|
|
102
132
|
extra_rdoc_files: []
|
103
133
|
files:
|
104
134
|
- .gitignore
|
135
|
+
- CHANGELOG.md
|
105
136
|
- Gemfile
|
106
137
|
- LICENSE.txt
|
107
138
|
- README.md
|
108
139
|
- Rakefile
|
109
140
|
- leanpub_api.gemspec
|
110
141
|
- lib/leanpub_api.rb
|
142
|
+
- lib/leanpub_api/base.rb
|
111
143
|
- lib/leanpub_api/book_summary.rb
|
144
|
+
- lib/leanpub_api/sales_summary.rb
|
112
145
|
- lib/leanpub_api/version.rb
|
113
146
|
- spec/fixtures/leanpub_cassettes/book_summary.yml
|
147
|
+
- spec/fixtures/leanpub_cassettes/sales_summary.yml
|
148
|
+
- spec/lib/leanpub_api/base_spec.rb
|
114
149
|
- spec/lib/leanpub_api/book_summary_spec.rb
|
150
|
+
- spec/lib/leanpub_api/sales_summary_spec.rb
|
115
151
|
- spec/spec_helper.rb
|
116
152
|
homepage: https://github.com/ruralocity/leanpub-api
|
117
153
|
licenses:
|
@@ -140,5 +176,8 @@ summary: A simple Ruby wrapper for the Leanpub API. Not affiliated with Leanpub
|
|
140
176
|
Ruboss Technology Corporation.
|
141
177
|
test_files:
|
142
178
|
- spec/fixtures/leanpub_cassettes/book_summary.yml
|
179
|
+
- spec/fixtures/leanpub_cassettes/sales_summary.yml
|
180
|
+
- spec/lib/leanpub_api/base_spec.rb
|
143
181
|
- spec/lib/leanpub_api/book_summary_spec.rb
|
182
|
+
- spec/lib/leanpub_api/sales_summary_spec.rb
|
144
183
|
- spec/spec_helper.rb
|