Skip to content
Browse files

More docs and examples

  • Loading branch information...
1 parent b356ebd commit e97e0ecbc799379497990d670a365ab0cf14b5a5 @hmarr hmarr committed
Showing with 294 additions and 6 deletions.
  1. +38 −6 README.md
  2. +120 −0 doc/GoCardless/Error.html
  3. +130 −0 doc/GoCardless/SignatureError.html
  4. +6 −0 lib/gocardless/client.rb
View
44 README.md
@@ -163,16 +163,33 @@ To modify the bill, alter the attributes and call the
APP_SECRET = '8oCITH2AVhaUYqJ+5hjyt8JUlSo5m/WTYLH8E/GO+TrBWdRK45lvoRt/zetr+t5Y'
# Create a new instance of the GoCardless API client
- client = GoCardless::Client.new(app_id, app_secret)
+ client = GoCardless::Client.new(APP_ID, APP_SECRET)
# Generate the OAuth 'authorize endpoint' URL
- client.authorize_url(:redirect_uri => 'http://mywebsite.com/cb')
+ authorize_url = client.authorize_url(:redirect_uri => 'http://mywebsite.com/cb')
+
+ # Now, redirect the user (merchant) to 'authorize_url'. In Rails this would
+ # look like:
+ #
+ # redirect_to authorize_url
+ #
+ # They will be presented with a screen where they confirm the link between
+ # their merchant account and your app. Once they are done, they will be
+ # redirected back to the 'redirect_url' you provided.
+
+ # Now you need to retrieve the authorization code from the query string
+ # parameters:
+ #
+ # auth_code = params[:auth_code]
+ #
+ # Then exchange the authorization code for an access token:
- # Once the authorization code has been retrieved, exchange it for an access token
- auth_code = params[:auth_code]
client.fetch_access_token(auth_code, :redirect_uri => 'http://mywebsite.com/cb')
- # The API client will associated with a merchant account
+ # The access token should be saved to the database alongside the merchant.
+ # You can get the access token using 'client.access_token'
+
+ # The API client will be associated with a merchant account
client.merchant # => <GoCardless::Merchant ...>
# The client allows you to look up most resources by their id
@@ -185,5 +202,20 @@ To modify the bill, alter the attributes and call the
subscription = client.subscription(5)
subscription.merchant # => <GoCardless::Merchant ...>
- # Create a new bill
+ # To create a new subscription, generate the appropirate URL:
+ url = client.new_subscription_url(:frequency_unit => :week,
+ :frequency_length => 6,
+ :amount => 30,
+ :description => 'Premium membership')
+
+ # Then redirect the user to the URL:
+ #
+ # redirect_to url
+ #
+ # When the user is redirected back to your site, you need to confirm the
+ # new subscription (assuming params is the query-string parameters):
+ subscription = client.confirm_resource(params)
+
+ # Create a new bill via the API under a pre authorization:
client.merchant.pre_authorizations.first.create_bill(500) # £5.00 bill
+
View
120 doc/GoCardless/Error.html
@@ -0,0 +1,120 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>
+ Exception: GoCardless::Error
+
+ &mdash; Documentation by YARD 0.7.2
+
+</title>
+
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
+
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
+
+<script type="text/javascript" charset="utf-8">
+ relpath = '..';
+ if (relpath != '') relpath += '/';
+</script>
+
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
+
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
+
+
+ </head>
+ <body>
+ <script type="text/javascript" charset="utf-8">
+ if (window.top.frames.main) document.body.className = 'frames';
+ </script>
+
+ <div id="header">
+ <div id="menu">
+
+ <a href="../_index.html">Index (E)</a> &raquo;
+ <span class='title'><span class='object_link'><a href="../GoCardless.html" title="GoCardless (module)">GoCardless</a></span></span>
+ &raquo;
+ <span class="title">Error</span>
+
+
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
+</div>
+
+ <div id="search">
+
+ <a id="class_list_link" href="#">Class List</a>
+
+ <a id="method_list_link" href="#">Method List</a>
+
+ <a id="file_list_link" href="#">File List</a>
+
+</div>
+ <div class="clear"></div>
+ </div>
+
+ <iframe id="search_frame"></iframe>
+
+ <div id="content"><h1>Exception: GoCardless::Error
+
+
+
+</h1>
+
+<dl class="box">
+
+ <dt class="r1">Inherits:</dt>
+ <dd class="r1">
+ <span class="inheritName">StandardError</span>
+
+ <ul class="fullTree">
+ <li>Object</li>
+
+ <li class="next">StandardError</li>
+
+ <li class="next">GoCardless::Error</li>
+
+ </ul>
+ <a href="#" class="inheritanceTree">show all</a>
+
+ </dd>
+
+
+
+
+
+
+
+
+
+ <dt class="r2 last">Defined in:</dt>
+ <dd class="r2 last">lib/gocardless/errors.rb</dd>
+
+</dl>
+<div class="clear"></div>
+
+<div id="subclasses">
+ <h2>Direct Known Subclasses</h2>
+ <p class="children"><span class='object_link'><a href="ApiError.html" title="GoCardless::ApiError (class)">ApiError</a></span>, <span class='object_link'><a href="SignatureError.html" title="GoCardless::SignatureError (class)">SignatureError</a></span></p>
+</div>
+
+
+
+
+
+
+
+
+
+
+</div>
+
+ <div id="footer">
+ Generated on Wed Aug 10 19:15:39 2011 by
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
+ 0.7.2 (ruby-1.8.7).
+</div>
+
+ </body>
+</html>
View
130 doc/GoCardless/SignatureError.html
@@ -0,0 +1,130 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<title>
+ Exception: GoCardless::SignatureError
+
+ &mdash; Documentation by YARD 0.7.2
+
+</title>
+
+ <link rel="stylesheet" href="../css/style.css" type="text/css" media="screen" charset="utf-8" />
+
+ <link rel="stylesheet" href="../css/common.css" type="text/css" media="screen" charset="utf-8" />
+
+<script type="text/javascript" charset="utf-8">
+ relpath = '..';
+ if (relpath != '') relpath += '/';
+</script>
+
+ <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>
+
+ <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>
+
+
+ </head>
+ <body>
+ <script type="text/javascript" charset="utf-8">
+ if (window.top.frames.main) document.body.className = 'frames';
+ </script>
+
+ <div id="header">
+ <div id="menu">
+
+ <a href="../_index.html">Index (S)</a> &raquo;
+ <span class='title'><span class='object_link'><a href="../GoCardless.html" title="GoCardless (module)">GoCardless</a></span></span>
+ &raquo;
+ <span class="title">SignatureError</span>
+
+
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
+</div>
+
+ <div id="search">
+
+ <a id="class_list_link" href="#">Class List</a>
+
+ <a id="method_list_link" href="#">Method List</a>
+
+ <a id="file_list_link" href="#">File List</a>
+
+</div>
+ <div class="clear"></div>
+ </div>
+
+ <iframe id="search_frame"></iframe>
+
+ <div id="content"><h1>Exception: GoCardless::SignatureError
+
+
+
+</h1>
+
+<dl class="box">
+
+ <dt class="r1">Inherits:</dt>
+ <dd class="r1">
+ <span class="inheritName"><span class='object_link'><a href="Error.html" title="GoCardless::Error (class)">Error</a></span></span>
+
+ <ul class="fullTree">
+ <li>Object</li>
+
+ <li class="next">StandardError</li>
+
+ <li class="next"><span class='object_link'><a href="Error.html" title="GoCardless::Error (class)">Error</a></span></li>
+
+ <li class="next">GoCardless::SignatureError</li>
+
+ </ul>
+ <a href="#" class="inheritanceTree">show all</a>
+
+ </dd>
+
+
+
+
+
+
+
+
+
+ <dt class="r2 last">Defined in:</dt>
+ <dd class="r2 last">lib/gocardless/errors.rb</dd>
+
+</dl>
+<div class="clear"></div>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</div>
+
+ <div id="footer">
+ Generated on Wed Aug 10 19:15:40 2011 by
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
+ 0.7.2 (ruby-1.8.7).
+</div>
+
+ </body>
+</html>
View
6 lib/gocardless/client.rb
@@ -221,6 +221,12 @@ def encode_params(params, ns = nil)
end.sort * '&'
end
+ # Send a request to the GoCardless API servers
+ #
+ # @param [Symbol] method the HTTP method to use (e.g. +:get+, +:post+)
+ # @param [String] path the path fragment of the URL
+ # @option [String] body the request body
+ # @option [Hash] params query string parameters
def request(method, path, opts = {})
opts[:headers] = { 'Accept' => 'application/json' }
opts[:headers]['Content-Type'] = 'application/json' unless method == :get

0 comments on commit e97e0ec

Please sign in to comment.
Something went wrong with that request. Please try again.