unicodeveloper/laravel-leanpub

为 Laravel 5 的 Leanpub 包

1.0.1 2015-11-20 14:10 UTC

This package is auto-updated.

Last update: 2024-09-07 17:55:45 UTC


README

Latest Stable Version License Build Status Quality Score Total Downloads

Laravel 5 包用于与 Leanpub 一起工作。非常容易使用。提供 Facade 和依赖注入的使用

免责声明:Leanpub 是加拿大不列颠哥伦比亚省注册的 Ruboss Technology Corporation 的服务。我使用他们的服务自行出版了一本书,但除此之外,我与他们没有任何关联。

安装

需要 PHP 5.5+ 或 HHVM 3.3+ 以及 Composer。

首先,通过 Composer 拉取该包。

$ composer require unicodeveloper/laravel-leanpub

另一个选择是直接将以下行添加到您的 composer.json 文件的 require 块中。

"unicodeveloper/laravel-leanpub": "1.0.*"

然后运行 composer installcomposer update 来下载它并更新自动加载器。

将以下内容添加到您的 config/app.php 文件中的 providers 数组中

// Laravel 5: config/app.php

'providers' => [
    ...
    Unicodeveloper\Leanpub\LeanpubServiceProvider::class,
    ...
];

该包还附带一个 facade

// Laravel 5: config/app.php

'aliases' => [
    ...
    'Leanpub' => Unicodeveloper\Leanpub\Facades\Leanpub::class,
    ...
]

通过运行以下命令发布配置文件

php artisan vendor:publish

配置文件现在位于 config/leanpub.php

配置

这是 config 目录中的 leanpub.php 文件。

/**
 *  Config file that a developer can insert the api key from Leanpub
 */
return [
    'API_KEY' => ''
];

使用方法

您需要您的书籍缩略名和 API 密钥值,这两个值都可以通过 访问您的 Leanpub 账户 获取。

LeanpubManager

这是最感兴趣的类。它绑定到 ioc 容器上的 'laravel-leanpub',可以使用 Facades\Leanpub facade 访问。

Facades\Leanpub

此 facade 将动态地将静态方法调用传递到 ioc 容器中的 'laravel-leanpub' 对象,默认情况下是 LeanpubManager 类。

示例

这里您可以看到一个示例,说明这个包是多么简单易用。

use Unicodeveloper\Leanpub\Facades\Leanpub;
// or you can alias this in config/app.php like I mentioned initially above

Book Summary Data

Leanpub::getBook($book_slug)->id;
// e.g sample $book_slug is phptherightway returns 11146

Leanpub::getBook($book_slug)->about_the_book;
// e.g sample $book_slug is phptherightway returns

 <p><em>There is no canonical way to use PHP</em>. This website aims to introduce new PHP developers to some topics which they may not discover until it is too late, and aims to give seasoned pros some fresh ideas on those topics they’ve been doing for years without ever reconsidering. This ebook will also not tell you which tools to use, but instead offer suggestions for multiple options, when possible explaining the differences in approach and use-case.</p>\r\n
 <p>This is a living document and will continue to be updated with more helpful information and examples as they become available.</p>

Leanpub::getBook($book_slug)->title;
// e.g sample $book_slug is phptherightway returns PHP: The "Right" Way

Leanpub::getBook($book_slug)->total_copies_sold;
// e.g sample $book_slug is phptherightway returns 12056

Leanpub::getBook($book_slug)->word_count_published;
// e.g sample $book_slug is phptherightway returns 15849

Leanpub::getBook($book_slug)->author_string;
// e.g sample $book_slug is phptherightway returns "Phil Sturgeon and Josh Lockhart"

Leanpub::getBook($book_slug)->url;
// e.g sample $book_slug is phptherightway returns "http://leanpub.com/phptherightway"

Leanpub::getBook($book_slug)->title_page_url;
// e.g sample $book_slug is phptherightway returns "https://s3.amazonaws.com/titlepages.leanpub.com/phptherightway/original?1425544606"

Leanpub::getBook($book_slug)->minimum_price;
// e.g sample $book_slug is phptherightway returns 0.0

Leanpub::getBook($book_slug)->suggested_price;
// e.g sample $book_slug is phptherightway returns 0.0

Leanpub::getBook($book_slug)->image;
// e.g sample $book_slug is phptherightway returns "https://s3.amazonaws.com/titlepages.leanpub.com/phptherightway/medium?1425544606"

Leanpub::getBook($book_slug)->isFree;
// e.g sample $book_slug is phptherightway returns true

Leanpub::getBook($book_slug)->last_published_at;
// e.g sample $book_slug is phptherightway returns "2015-01-05T16:37:01Z"

Leanpub::getBook($book_slug)->meta_description;
// e.g sample $book_slug is phptherightway returns null

Leanpub::getBook($book_slug)->page_count_published;
// e.g sample $book_slug is phptherightway returns 70

Leanpub::getBook($book_slug)->subtitle;
// e.g sample $book_slug is phptherightway returns "Your guide to PHP best practices, coding standards,  and authoritative tutorials."

Leanpub::getBook($book_slug)->total_revenue;
// e.g sample $book_slug is phptherightway returns the price in revenue if the book is not free. For a book that is free like this, there is no `total_revenue` attribute

Leanpub::getBook($book_slug)->possible_reader_count;
// e.g sample $book_slug is phptherightway returns 12052

Sales Summary Data

Leanpub::getSalesInfo($book_slug)->book
Leanpub::getSalesInfo($book_slug)->url
Leanpub::getSalesInfo($book_slug)->total_author_royalties
Leanpub::getSalesInfo($book_slug)->total_book_royalties
Leanpub::getSalesInfo($book_slug)->num_happy_readers
Leanpub::getSalesInfo($book_slug)->num_happy_paid_purchases
Leanpub::getSalesInfo($book_slug)->num_refunded_purchases
Leanpub::getSalesInfo($book_slug)->unpaid_royalties
Leanpub::getSalesInfo($book_slug)->royalties_currently_due
Leanpub::getSalesInfo($book_slug)->royalties_due_on_first_of_next_month
Leanpub::getSalesInfo($book_slug)->paid_royalties

TODO

为其他 API 功能添加包装器

  • 所有销售数据
  • 预览功能
  • 发布功能
  • 预览/发布作业状态
  • 优惠券管理
  • 测试

更改日志

请参阅 CHANGELOG 了解最近更改的信息。

测试

您可以使用以下命令运行测试

vendor/bin/phpunit run

或者,您也可以这样运行测试

composer test

贡献

请参阅 CONTRIBUTING 了解详细信息。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件

安全

如果您发现任何安全相关的问题,请通过电子邮件 prosperotemuyiwa@gmail.com 联系,而不是使用问题跟踪器。