walletkit 1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in walletkit-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 WalletKit
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Walletkit::Ruby
2
+
3
+ Ruby SDK for WalletKit
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'walletkit-ruby'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install walletkit-ruby
18
+
19
+ ## Usage
20
+
21
+ TODO
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module Walletkit
2
+ VERSION = "1.0"
3
+ end
@@ -0,0 +1,136 @@
1
+ require "walletkit-ruby/version"
2
+ require "bundler/setup"
3
+ require "net/http"
4
+ require "json"
5
+
6
+ module Walletkit
7
+ #module Ruby
8
+ class WalletKit
9
+ # Intializes REST client
10
+ #
11
+ # * *Args* :
12
+ # - +api_key+ -> the API key
13
+ # - +brand_id+ -> the brand id
14
+ #
15
+ def initialize(api_key,brand_id)
16
+ @api = 'api.walletkit.com'
17
+ @api_key, @brand_id = api_key, brand_id
18
+ @headers = {
19
+ "api-key" => @api_key,
20
+ "brand-id" => @brand_id,
21
+ "Content-Type" => 'application/json'
22
+ }
23
+ @http = Net::HTTP.new(@api)
24
+ end
25
+
26
+ # Creates a pass template
27
+ #
28
+ # * *Args* :
29
+ # - +template_data+ -> the pass template data as a hash
30
+ # * *Returns* :
31
+ # - Json string containing the template id
32
+ #
33
+ def create_pass_template(template_data)
34
+ begin
35
+ request = Net::HTTP::Post.new('/v1/passes', @headers)
36
+ request.body = template_data.to_json
37
+ response = @http.request(request)
38
+ rescue Exception => e
39
+ p e.message
40
+ p e.backtrace
41
+ end
42
+ response.body
43
+ end
44
+
45
+ # Gets the list of all existing pass templates
46
+ #
47
+ # * *Returns* :
48
+ # - Json string containing id and description of templates
49
+ #
50
+ def get_pass_template_list()
51
+ begin
52
+ response = @http.request_get('/v1/passes', @headers)
53
+ rescue Exception => e
54
+ p e.message
55
+ p e.backtrace
56
+ end
57
+ response.body
58
+ end
59
+
60
+ # Gets information about a pass template
61
+ #
62
+ # * *Args* :
63
+ # - +template_id+ -> the pass template id
64
+ # * *Returns* :
65
+ # - Json string containing information about the template
66
+ #
67
+ def get_pass_template_info(template_id)
68
+ begin
69
+ response = @http.request_get('/v1/passes/' + template_id.to_s, @headers)
70
+ rescue Exception => e
71
+ p e.message
72
+ p e.backtrace
73
+ end
74
+ response.body
75
+ end
76
+
77
+ # Creates a pass
78
+ #
79
+ # * *Args* :
80
+ # - +template_id+ -> the pass template id
81
+ # - +pass_data+ -> the pass data as a hash
82
+ # * *Returns* :
83
+ # - Json string containing information about the pass
84
+ #
85
+ def create_pass(template_id, pass_data)
86
+ begin
87
+ request = Net::HTTP::Post.new('/v1/passes/' + template_id.to_s, @headers)
88
+ request.body = pass_data.to_json
89
+ response = @http.request(request)
90
+ rescue Exception => e
91
+ p e.message
92
+ p e.backtrace
93
+ end
94
+ response.body
95
+ end
96
+
97
+ # Updates a pass
98
+ #
99
+ # * *Args* :
100
+ # - +template_id+ -> the pass template id
101
+ # - +pass_data+ -> the pass data as a hash
102
+ # * *Returns* :
103
+ # - Json string containing information about the pass
104
+ #
105
+ def update_pass(template_id, pass_data)
106
+ begin
107
+ request = Net::HTTP::Put.new('/v1/passes/' + template_id.to_s, @headers)
108
+ request.body = pass_data.to_json
109
+ response = @http.request(request)
110
+ rescue Exception => e
111
+ p e.message
112
+ p e.backtrace
113
+ end
114
+ response.body
115
+ end
116
+
117
+ # Deletes a pass template
118
+ #
119
+ # * *Args* :
120
+ # - +template_id+ -> the pass template id
121
+ # * *Returns* :
122
+ # - Json string containing the server response
123
+ #
124
+ def delete_pass_template(template_id)
125
+ begin
126
+ request = Net::HTTP::Delete.new('/v1/passes/' + template_id.to_s, @headers)
127
+ response = @http.request(request)
128
+ rescue Exception => e
129
+ p e.message
130
+ p e.backtrace
131
+ end
132
+ response.body
133
+ end
134
+ end
135
+ # end
136
+ end
@@ -0,0 +1,62 @@
1
+ require 'test/unit'
2
+ require 'walletkit-ruby'
3
+
4
+ class WKUnitTests < Test::Unit::TestCase
5
+
6
+ def test_walletkit_client()
7
+ template_data={
8
+ "logotext" => "Brand name" ,
9
+ "background" => "http://www.example.com/yourBackground.png",
10
+ "description" => "Description of the pass" ,
11
+ "icon" => "http://www.example.com/yourIcon.png" ,
12
+ "pass_type" => "coupon"
13
+ }
14
+ pass_create_data = {
15
+ "keys" => [{
16
+ "key" => "Destination",
17
+ "value" => "SFO"
18
+ },
19
+ {
20
+ "key" => "Departure",
21
+ "value" => "Chennai,India"
22
+ }],
23
+ "location" => [{
24
+ "latitude" => 178.67 ,
25
+ "longitude" => 167.60
26
+ }]
27
+ }
28
+
29
+ wkclient = Walletkit::WalletKit.new('<api key>','<brand id>')
30
+ puts "Template List"
31
+ puts wkclient.get_pass_template_list()
32
+ puts "Create pass template"
33
+ response = wkclient.create_pass_template(template_data)
34
+ template_id = JSON.parse(response)['id']
35
+ puts template_id
36
+ puts "Get template info"
37
+ puts wkclient.get_pass_template_info(template_id)
38
+ puts "Create pass"
39
+ puts wkclient.create_pass(template_id, pass_create_data)
40
+
41
+ pass_update_data={
42
+ "id" => template_id.to_s,
43
+ "keys" => [{
44
+ "key" => "Destination",
45
+ "value" => "SFO"
46
+ },
47
+ {
48
+ "key" => "Departure",
49
+ "value" => "Chennai,India"
50
+ }],
51
+ "updatekeys" => [{
52
+
53
+ "key" => "Departure",
54
+ "value" => "Mumbai,India"
55
+ }]
56
+ }
57
+ puts "Update pass"
58
+ puts wkclient.update_pass(template_id, pass_update_data)
59
+ puts "Delete pass template"
60
+ puts wkclient.delete_pass_template(template_id)
61
+ end
62
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require './lib/walletkit-ruby/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "walletkit"
8
+ gem.version = Walletkit::VERSION
9
+ gem.authors = ["walletkit"]
10
+ gem.email = ["support@walletkit.com"]
11
+ gem.description = %q{WalletKit Ruby SDK}
12
+ gem.summary = %q{Ruby SDK for WalletKit}
13
+ gem.homepage = "https://github.com/walletkit/walletkit-ruby.git"
14
+ gem.license = "https://walletkit.com/legal"
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+
21
+ gem.add_development_dependency "json"
22
+ gem.add_development_dependency "net-http-persistent"
23
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: walletkit
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - walletkit
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: json
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: net-http-persistent
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: WalletKit Ruby SDK
47
+ email:
48
+ - support@walletkit.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/walletkit-ruby.rb
59
+ - lib/walletkit-ruby/version.rb
60
+ - test/test_walletkit-ruby.rb
61
+ - walletkit-ruby.gemspec
62
+ homepage: https://github.com/walletkit/walletkit-ruby.git
63
+ licenses:
64
+ - https://walletkit.com/legal
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Ruby SDK for WalletKit
87
+ test_files:
88
+ - test/test_walletkit-ruby.rb