Skip to content

Commit

Permalink
added satoshi view helper to convert satoshi to other unit e.g. bitco…
Browse files Browse the repository at this point in the history
…in, updated docs
  • Loading branch information
Sandro Keil committed Jun 27, 2014
1 parent 2481ab4 commit 0f65315
Show file tree
Hide file tree
Showing 11 changed files with 492 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Version 1.0.0 - TBA

* Satoshi view helper which converts satoshi to other unit e.g. bitcoin
* Validator support via input filter
* Service plugin manager for responses, requests and input filter
* Hydrator strategies for address list and addresses
Expand Down
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# CONTRIBUTING

## RESOURCES

If you wish to contribute to Zend Framework, please be sure to read to the following resources:

- Coding Standards: [PSR-0/1/2/4](https://github.com/php-fig/fig-standards/tree/master/accepted)
- Git Guide: [README-GIT.md](README-GIT.md)

If you are working on new features, or refactoring an existing
component, please create a proposal. You can do this in on the RFC's
page, https://github.com/sandrokeil/BlockchainWalletApi/wiki/RFCs.

## RUNNING TESTS

To run tests:

- Make sure you have a recent version of PHPUnit installed; 3.7.0
minimally.
- Be sure you are in the root directory
- Execute PHPUnit

```sh
% phpunit
```

You can turn on conditional tests with the TestConfig.php file.
To do so:

- Enter the `test/` subdirectory.
- Copy `TestConfig.php.dist` file to `TestConfig.php`
- Edit `TestConfig.php` to enable any specific functionality you want to test, as well as to provide test values to
utilize.
116 changes: 116 additions & 0 deletions README-GIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# USING THE GIT REPOSITORY

## Setup your own public github repository

Your first step is to establish a public repository from which i can pull your work into the master repository.

1. Setup a GitHub account (http://github.com/), if you haven't yet
2. Fork the BlockchainWalletApi repository (http://github.com/sandrokeil/BlockchainWalletApi)
3. Clone your fork locally and enter it (use your own GitHub username in the statement below)

```sh
% git clone git@github.com:<username>/BlockchainWalletApi.git
% cd BlockchainWalletApi
```

4. Add a remote to the canonical BlockchainWalletApi repository, so you can keep your fork
up-to-date:

```sh
% git remote add upstream https://github.com/sandrokeil/BlockchainWalletApi.git
% git fetch upstream
```

## Keeping Up-to-Date

Periodically, you should update your fork to match the canonical BlockchainWalletApi repository. we have
added a remote to the BlockchainWalletApi repository, which allows you to do the following:

```sh
% git checkout master
% git pull upstream master
- OPTIONALLY, to keep your remote up-to-date -
% git push origin
```

If you're tracking other branches -- for example, the "develop" branch, where new feature development occurs --
you'll want to do the same operations for that branch; simply substitute "develop" for "master".

## Working on BlockchainWalletApi

When working on BlockchainWalletApi, we recommend you do each new feature or bugfix in a new branch. This simplifies the
task of code review as well as of merging your changes into the canonical repository.

A typical work flow will then consist of the following:

1. Create a new local branch based off your master branch.
2. Switch to your new local branch. (This step can be combined with the previous step with the use of `git checkout -b`.)
3. Do some work, commit, repeat as necessary.
4. Push the local branch to your remote repository.
5. Send a pull request.

The mechanics of this process are actually quite trivial. Below, we will create a branch for fixing an issue in the tracker.

```sh
% git checkout -b 3452
Switched to a new branch '3452'
```
... do some work ...

```sh
% git commit
```
... write your log message ...

```sh
% git push origin HEAD:3452
Counting objects: 38, done.
Delta compression using up to 2 threads.
Compression objects: 100% (18/18), done.
Writing objects: 100% (20/20), 8.19KiB, done.
Total 20 (delta 12), reused 0 (delta 0)
To ssh://git@github.com/sandrokeil/BlockchainWalletApi.git
g5342..9k3532 HEAD -> master
```

You can do the pull request from github. Navigate to your repository, select the branch you just created, and then
select the "Pull Request" button in the upper right. Select the user "sandrokeil" as the recipient.

### What branch to issue the pull request against?

Which branch should you issue a pull request against?

- For fixes against the stable release, issue the pull request against the "master" branch.
- For new features, or fixes that introduce new elements to the public API
(such as new public methods or properties), issue the pull request against the "develop" branch.

## Branch Cleanup

As you might imagine, if you are a frequent contributor, you'll start to get a ton of branches both locally and on
your remote.

Once you know that your changes have been accepted to the master repository, we suggest doing some cleanup of these
branches.

- Local branch cleanup

```sh
% git branch -d <branchname>
```

- Remote branch removal

```sh
% git push origin :<branchname>
```


## FEEDS AND EMAILS

RSS feeds may be found at:

`https://github.com/sandrokeil/BlockchainWalletApi/commits/<branch>.atom`

where &lt;branch&gt; is a branch in the repository.

To subscribe to git email notifications, simply watch or fork the BlockchainWalletApi repository on GitHub.
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Zend Framework 2 client library for [blockchain wallet api](https://blockchain.i
* **Adapts To Your Needs.** There are several possibilities to configure this module.
* **Well tested.** Besides unit test and continuous integration/inspection this solution is also ready for production use.
* **Great foundations.** Based on [Zend Framework 2](https://github.com/zendframework/zf2) and [Easy Config](https://github.com/sandrokeil/EasyConfig)
* **Every change is tracked**. Want to know whats new? Take a look at [CHANGELOG.md](https://github.com/sandrokeil/BlockchainWalletApi/blob/master/CHANGELOG.md)
* **Listen to your ideas.** Have a great idea? Bring your tested pull request or open a new issue.
* **Every change is tracked**. Want to know whats new? Take a look at [CHANGELOG.md](CHANGELOG.md)
* **Listen to your ideas.** Have a great idea? Bring your tested pull request or open a new issue. See [CONTRIBUTING.md](CONTRIBUTING.md)

## Installation

Expand Down Expand Up @@ -50,11 +50,10 @@ These request classes matches to api methods
* AddressUnarchive => unarchive_address
* AutoConsolidateAddresses => auto_consolidate

Here is an example how to send bitcoins to an bitcoin address:
Here is an example how to send bitcoins to a bitcoin address:

```php
<?php

use Sake\BlockchainWalletApi;

// $sl is the service locator
Expand Down Expand Up @@ -84,7 +83,6 @@ Here is an example how to retrieve wallet balance:

```php
<?php

use Sake\BlockchainWalletApi;

// $sl is the service locator
Expand All @@ -107,6 +105,19 @@ try {
// error handling
}
```
Here is an example how to use satoshi view helper to convert satoshi to other unit:

```php
<?php
// assume we are in a template

/* @var $response BlockchainWalletApi\Response\WalletBalance */
echo $this->satoshi($response->getBalanace(), 'BTC'); // Bitcoin
// or
echo $this->satoshi($response->getBalanace(), 'mBTC'); // Milli Bits
// or
echo $this->satoshi($response->getBalanace(), 'uBTC'); // Micro Bitcoin
```

## Configuration
Connection parameters can be defined in the application configuration:
Expand Down Expand Up @@ -139,7 +150,5 @@ return array(
* `sake_bwa.service.input_filter`: a \Sake\BlockchainWalletApi\Service\InputFilterPluginManager Service plugin manager to create input filter via api method name
* `sake_bwa.service.hydrator`: a \Zend\Stdlib\Hydrator\ClassMethods instance with strategies and filters for requests/responses

## Todo's
* More unit tests
* Satoshi converter/filter
* View Helper to display data
## Registered view helper
* `satoshi`: a \Zend\View\Helper\AbstractHelper instance which converts satoshi to other unit e.g. bitcoin
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"license": "BSD-3-Clause",
"type": "library",
"keywords": [
"blockhain",
"bitcoin",
"zf2",
"blockhain wallet api",
"bitcoin",
"blockhain",
"wallet",
"api",
"webservice",
Expand Down Expand Up @@ -39,9 +39,11 @@
"zendframework/zend-serializer": "~2.2",
"zendframework/zend-log": "~2.2",
"zendframework/zend-modulemanager": "~2.2",
"zendframework/zend-view": "~2.2",
"sandrokeil/citools": "~1.0"
},
"suggest": {
"zendframework/zend-view": "Zend\\View to use satoshi view helper",
"zendframework/zend-modulemanager": "Zend\\ModuleManager to use default module configuration e.g. services"
}
}
2 changes: 1 addition & 1 deletion config/blockchainwalletapi.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ return array(
'connection' => array(
'default' => array(
'options' => array(
// see \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions for all configurations
// see \Sake\BlockchainWalletApi\Service\BlockchainWalletOptions for all options
'url' => 'https://blockchain.info/de/merchant/', // note on your country
'guid' => 'your My Wallet identifier (found on the login page)',
'main_password' => 'Your Main My wallet password',
Expand Down
14 changes: 14 additions & 0 deletions config/view_helper.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* Sake
*
* @link http://github.com/sandrokeil/BlockchainWalletApi for the canonical source repository
* @copyright Copyright (c) 2014 Sandro Keil
* @license http://github.com/sandrokeil/BlockchainWalletApi/blob/master/LICENSE.txt New BSD License
*/

return array(
'invokables' => array(
'satoshi' => '\Sake\BlockchainWalletApi\View\Helper\Satoshi',
),
);
14 changes: 13 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
namespace Sake\BlockchainWalletApi;

use Zend\ModuleManager\Feature\ServiceProviderInterface;
use Zend\ModuleManager\Feature\ViewHelperProviderInterface;

/**
* This class initializes the BlockchainWalletApi module.
*/
class Module implements ServiceProviderInterface
class Module implements ServiceProviderInterface, ViewHelperProviderInterface
{
/**
* Return service config
Expand All @@ -26,4 +27,15 @@ public function getServiceConfig()
{
return require dirname(__DIR__) . '/config/service_manager.config.php';
}

/**
* Expected to return \Zend\ServiceManager\Config object or array to
* seed such an object.
*
* @return array
*/
public function getViewHelperConfig()
{
return require dirname(__DIR__) . '/config/view_helper.config.php';
}
}
3 changes: 1 addition & 2 deletions src/Service/BlockchainWallet.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Zend\Http\Request;
use Zend\Http\Response as HttpResponse;
use Sake\BlockchainWalletApi\Exception;
use Zend\InputFilter\InputFilter;

/**
* Blockchain wallet api service
Expand Down Expand Up @@ -82,7 +81,7 @@ public function send(RequestInterface $request)
*/
public function isValid(RequestInterface $request)
{
/* @var $inputFilter InputFilter */
/* @var $inputFilter \Zend\InputFilter\InputFilter */
$inputFilter = $this->getOptions()->getInputFilterPluginManager()->get($request->getMethod());
$inputFilter->setData($this->getOptions()->getHydrator()->extract($request));
return $inputFilter->isValid();
Expand Down

0 comments on commit 0f65315

Please sign in to comment.