lunks-wepay 0.0.2

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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/README +33 -0
  3. data/lib/lunks-wepay.rb +1 -0
  4. data/lib/wepay.rb +69 -0
  5. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8619a9f021d8a2f5bc76db6c40edfac4d42e5552
4
+ data.tar.gz: b84cd3db46cf44f0093f790ac8214cbf98c475ea
5
+ SHA512:
6
+ metadata.gz: f0a6f5c063e9cb2c1bd185c578636e06285d020e2dd2cba58033b39475bb76c5c69537576b5c9ce09c8b0f98393c9922f3926576fec947ff97dd5295e76f36e6
7
+ data.tar.gz: f52a4881faf0f328e450e5bfce864d6dba4cc89c13827d90276991daaa2d2942cd45e7598e9dbc99a9a2c57154eda5f27cd6292878b8e88f195b7935a11a3237
data/README ADDED
@@ -0,0 +1,33 @@
1
+ WePay Ruby SDK
2
+
3
+ To use this SDK:
4
+
5
+ # creates a wepay object you can use to make calls.
6
+ # Set use_stage to true for test/stage, false for production.
7
+ wepay = WePay.new(client_id, client_secret, use_stage)
8
+
9
+ # get the authorization url
10
+ # you send the user to this url to authorize the application, they will return to your redirect with a code in the get parameters
11
+ redirect_uri = "http://myexamplesite.com/wepay"
12
+ url = wepay.oauth2_authorize_url(redirect_uri)
13
+ redirect_to(url)
14
+
15
+ # once you have the code you can get an access token
16
+ response = wepay.oauth2_token(code, redirect_uri)
17
+ access_token = response['access_token']
18
+
19
+
20
+ # makes a call to the /user endpoint (which requires no parameters)
21
+ response = wepay.call('/user', access_token)
22
+
23
+ # you can also open a payment account for the user
24
+ response = wepay.call('/account/create', access_token, {:name => "test account", "description" => "this is only a test" })
25
+
26
+
27
+ # switching to production
28
+ When you want to switch to production, change the _use_stage parameter on the WePay constructer to false.
29
+
30
+
31
+ check out our developer docs at https://stage.wepay.com/developer for more info
32
+
33
+ or email api@wepay.com if you have any questions.
@@ -0,0 +1 @@
1
+ require 'wepay'
@@ -0,0 +1,69 @@
1
+ require 'rubygems'
2
+ require 'uri'
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'net/https'
6
+ require 'cgi'
7
+
8
+ =begin
9
+ helps you make API calls to the WePay API v2
10
+ =end
11
+
12
+ class WePay
13
+
14
+ STAGE_API_ENDPOINT = "https://stage.wepayapi.com/v2"
15
+ STAGE_UI_ENDPOINT = "https://stage.wepay.com/v2"
16
+
17
+ PRODUCTION_API_ENDPOINT = "https://wepayapi.com/v2"
18
+ PRODUCTION_UI_ENDPOINT = "https://www.wepay.com/v2"
19
+
20
+ # initializes the API application, api_endpoint should be something like 'https://stage.wepay.com/v2'
21
+ def initialize(_client_id, _client_secret, _use_stage = true, _use_ssl = true)
22
+ @client_id = _client_id
23
+ @client_secret = _client_secret
24
+ if _use_stage
25
+ @api_endpoint = STAGE_API_ENDPOINT
26
+ @ui_endpoint = STAGE_UI_ENDPOINT
27
+ else
28
+ @api_endpoint = PRODUCTION_API_ENDPOINT
29
+ @ui_endpoint = PRODUCTION_UI_ENDPOINT
30
+ end
31
+ @use_ssl = _use_ssl
32
+ end
33
+
34
+ # make a call to the WePay API
35
+ def call(call, access_token = false, params = false)
36
+ # get the url
37
+ url = URI.parse(@api_endpoint + call)
38
+ # construct the call data and access token
39
+ call = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json', 'User-Agent' => 'WePay Ruby SDK'})
40
+ if params
41
+ call.body = params.to_json
42
+ end
43
+ if access_token
44
+ call.add_field('Authorization: Bearer', access_token);
45
+ end
46
+ # create the request object
47
+ request = Net::HTTP.new(url.host, url.port)
48
+ request.read_timeout = 30
49
+ request.use_ssl = @use_ssl
50
+ # make the call
51
+ response = request.start {|http| http.request(call) }
52
+ # returns JSON response as ruby hash
53
+ JSON.parse(response.body)
54
+ end
55
+
56
+ # this function returns the URL that you send the user to to authorize your API application
57
+ # the redirect_uri must be a full uri (ex https://www.wepay.com)
58
+ def oauth2_authorize_url(redirect_uri, user_email = false, user_name = false, permissions = "manage_accounts,view_balance,collect_payments,refund_payments,view_user")
59
+ url = @ui_endpoint + '/oauth2/authorize?client_id=' + @client_id.to_s + '&redirect_uri=' + redirect_uri + '&scope=' + permissions
60
+ url += user_name ? '&user_name=' + CGI::escape(user_name) : ''
61
+ url += user_email ? '&user_email=' + CGI::escape(user_email) : ''
62
+ end
63
+
64
+ #this function will make a call to the /v2/oauth2/token endpoint to exchange a code for an access_token
65
+ def oauth2_token(code, redirect_uri)
66
+ call('/oauth2/token', false, {'client_id' => @client_id, 'client_secret' => @client_secret, 'redirect_uri' => redirect_uri, 'code' => code })
67
+ end
68
+
69
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lunks-wepay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - WePay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2012-09-11 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The WePay Ruby SDK lets you easily make WePay API calls from ruby. This
14
+ versions adds a read_timeout of 30 seconds and removes the annoying p url that went
15
+ to the gem code.
16
+ email: api@wepay.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/lunks-wepay.rb
22
+ - lib/wepay.rb
23
+ - README
24
+ homepage: https://stage.wepay.com/developer
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Ruby SDK for the WePay API without the annoying puts
47
+ test_files: []