kayakoapi-ruby 1.0.4
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.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +66 -0
- data/Rakefile +1 -0
- data/bin/kayakoapi +42 -0
- data/kayakoapi-ruby.gemspec +21 -0
- data/lib/kayakoapi-ruby/apisig.rb +32 -0
- data/lib/kayakoapi-ruby/exceptions.rb +7 -0
- data/lib/kayakoapi-ruby/urlgenerator.rb +34 -0
- data/lib/kayakoapi-ruby/version.rb +3 -0
- data/lib/kayakoapi-ruby.rb +23 -0
- data/spec/apisig_spec.rb +34 -0
- data/spec/spec_helper.rb +2 -0
- metadata +79 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Peter Mellett
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Kayakoapi::Ruby
|
2
|
+
|
3
|
+
Basic ruby app to generate Kayako API URLS.
|
4
|
+
|
5
|
+
Currently prints the generated URL to the console.
|
6
|
+
|
7
|
+
Minutely tested.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
gem 'kayakoapi-ruby'
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install kayakoapi-ruby
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
$ kayakoapi-ruby - u url-base -k app-key -s app-secret
|
26
|
+
|
27
|
+
salt is randomly generated.
|
28
|
+
|
29
|
+
e.g.
|
30
|
+
|
31
|
+
$ kayakoapi-ruby -u http://my-api-url/
|
32
|
+
|
33
|
+
Output:
|
34
|
+
|
35
|
+
$ Generated URL: http://my-api-url/api/index.php?/Controller/Action&signature=%57%56%4A%65%4D%65+%31%4A%6B%34%33%4E%32%6C%56%6E/%70%4D%6D%33%5A%57%79%31%4F%51%31%50%62%34%76%67%74%47%41%4E%67%4A%42%35%45=&salt=5870184239&apikey=1234567890
|
36
|
+
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
45
|
+
|
46
|
+
## License
|
47
|
+
|
48
|
+
Copyright (c) 2013 Peter Mellett
|
49
|
+
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
51
|
+
of this software and associated documentation files (the "Software"), to deal
|
52
|
+
in the Software without restriction, including without limitation the rights
|
53
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
54
|
+
copies of the Software, and to permit persons to whom the Software is
|
55
|
+
furnished to do so, subject to the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be included in all
|
58
|
+
copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
61
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
62
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
63
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
64
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
65
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
66
|
+
SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/kayakoapi
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'kayakoapi-ruby'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
opts.banner = "Usage: kayakoapi-ruby [options]"
|
10
|
+
|
11
|
+
opts.on("-u", "--url [URL]", "Base URL for your API Call") do |url|
|
12
|
+
options[:url] = url
|
13
|
+
end
|
14
|
+
|
15
|
+
opts.on("-k", "--key [KEY]", "API Key from your Kayako Helpdesk") do |key|
|
16
|
+
options[:app_key] = key
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-s", "--secret [SECRET]", "API Secret from your Kayako Helpdesk") do |secret|
|
20
|
+
options[:secret] = secret
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
24
|
+
puts opts
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on_tail("--version", "Show version") do
|
29
|
+
puts "Kayako API URL Generator: v#{Kayakoapi::VERSION}"
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
end.parse!
|
33
|
+
|
34
|
+
[:url, :app_key, :secret].each do |setting|
|
35
|
+
if options[setting] == nil
|
36
|
+
print "Please enter a value for #{setting}: "
|
37
|
+
options[setting] = gets
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
app = Kayakoapi::App.new(options[:url], options[:app_key], options[:secret])
|
42
|
+
app.run
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'kayakoapi-ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "kayakoapi-ruby"
|
8
|
+
gem.version = Kayakoapi::VERSION
|
9
|
+
gem.authors = ["Peter Mellett"]
|
10
|
+
gem.email = ["bulletraven@gmail.com"]
|
11
|
+
gem.description = %q{Ruby Shoes app to generate Kayako API URLs.}
|
12
|
+
gem.summary = %q{Ruby Shoes app to generate Kayako Resolve API URLs.}
|
13
|
+
gem.homepage = "https://github.com/wadtech/kayakoapi-ruby"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec", ["~> 2.12"]
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Kayakoapi
|
2
|
+
# Required Libraries
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
class APISig
|
7
|
+
def initialize(key, secret)
|
8
|
+
@api_key = key
|
9
|
+
@secret_key = secret
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_salt()
|
13
|
+
@last_salt = rand(10000000000).to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def hash(key, salt)
|
17
|
+
OpenSSL::HMAC.digest('sha256', key, salt)
|
18
|
+
end
|
19
|
+
|
20
|
+
def b64encode(hash)
|
21
|
+
signature = Base64.encode64(hash);
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_signature()
|
25
|
+
self.get_salt
|
26
|
+
hash = self.hash(@secret_key, @last_salt)
|
27
|
+
b64hash = self.b64encode hash
|
28
|
+
@last_hash = URLGenerator::urlncode b64hash.strip
|
29
|
+
return { signature: @last_hash, salt: @last_salt, apikey: @api_key }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Kayakoapi
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
class URLGenerator
|
5
|
+
def initialize(url_root)
|
6
|
+
@url_root = url_root
|
7
|
+
@params = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def append_to_url(key, value)
|
11
|
+
@params[key] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def full_url
|
15
|
+
current_url = @url_root
|
16
|
+
if @params.empty?
|
17
|
+
raise NoURLParametersException.new(msg: "Params hash is empty while attempting to build a URL.")
|
18
|
+
else
|
19
|
+
@params.each do |key, value|
|
20
|
+
current_url += "&#{key}=#{value}"
|
21
|
+
end
|
22
|
+
return current_url
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def first_param?
|
27
|
+
@first_param
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.urlncode(string)
|
31
|
+
URI.escape(string, Regexp.new("[Generating an API Signature^#{URI::PATTERN::UNRESERVED}]"))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "kayakoapi-ruby/version"
|
2
|
+
require "kayakoapi-ruby/apisig"
|
3
|
+
require "kayakoapi-ruby/urlgenerator"
|
4
|
+
|
5
|
+
module Kayakoapi
|
6
|
+
require 'uri'
|
7
|
+
|
8
|
+
class App
|
9
|
+
def initialize(base_url, app_key, app_secret)
|
10
|
+
@api_sig = APISig.new(app_key, app_secret)
|
11
|
+
@url_builder = URLGenerator.new(base_url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
@api_sig.new_signature.each { |key, value| @url_builder.append_to_url(key, value) }
|
16
|
+
begin
|
17
|
+
puts "Generated URL: #{@url_builder.full_url}"
|
18
|
+
rescue => e
|
19
|
+
puts "URL Could not be generated, no parameters were appended to the URL."
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/apisig_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "kayakoapi-ruby/apisig"
|
3
|
+
require "kayakoapi-ruby/urlgenerator"
|
4
|
+
|
5
|
+
describe "APISig" do
|
6
|
+
before :each do
|
7
|
+
@apisig = Kayakoapi::APISig.new("one", "two")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should generate a random salt" do
|
11
|
+
@salt = @apisig.get_salt
|
12
|
+
@salt.should_not be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should hash a key and a salt" do
|
16
|
+
hash = @apisig.hash("secret key", "random salt")
|
17
|
+
hash.should eq "\xDA>\xD7\x8B>\x150\xC2\x98\r\xA4\xA6\\o\xFDf\xE1&o\x19N\xF6\xFE\xEF0\x1C7\rR\x99/O"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should encode a string into base64" do
|
21
|
+
string = @apisig.b64encode("String")
|
22
|
+
string.should eq "U3RyaW5n\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return a hash when asked to create a new signature" do
|
26
|
+
urlgen = double("urlgenerator")
|
27
|
+
urlgen.stub!(:urlencode).and_return "encoded"
|
28
|
+
|
29
|
+
result = @apisig.new_signature
|
30
|
+
result[:signature].should_not be_nil
|
31
|
+
result[:salt].should_not be_nil
|
32
|
+
result[:apikey].should_not be_nil
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kayakoapi-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Peter Mellett
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '2.12'
|
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: '2.12'
|
30
|
+
description: Ruby Shoes app to generate Kayako API URLs.
|
31
|
+
email:
|
32
|
+
- bulletraven@gmail.com
|
33
|
+
executables:
|
34
|
+
- kayakoapi
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- .rspec
|
40
|
+
- Gemfile
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/kayakoapi
|
45
|
+
- kayakoapi-ruby.gemspec
|
46
|
+
- lib/kayakoapi-ruby.rb
|
47
|
+
- lib/kayakoapi-ruby/apisig.rb
|
48
|
+
- lib/kayakoapi-ruby/exceptions.rb
|
49
|
+
- lib/kayakoapi-ruby/urlgenerator.rb
|
50
|
+
- lib/kayakoapi-ruby/version.rb
|
51
|
+
- spec/apisig_spec.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
homepage: https://github.com/wadtech/kayakoapi-ruby
|
54
|
+
licenses: []
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ! '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 1.8.24
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: Ruby Shoes app to generate Kayako Resolve API URLs.
|
77
|
+
test_files:
|
78
|
+
- spec/apisig_spec.rb
|
79
|
+
- spec/spec_helper.rb
|