kayakoapi-ruby 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -14
- data/lib/kayakoapi-ruby.rb +17 -14
- data/lib/kayakoapi-ruby/apisig.rb +5 -6
- data/lib/kayakoapi-ruby/exceptions.rb +1 -1
- data/lib/kayakoapi-ruby/urlgenerator.rb +11 -3
- data/lib/kayakoapi-ruby/version.rb +1 -1
- data/spec/apisig_spec.rb +0 -1
- data/spec/spec_helper.rb +3 -0
- data/spec/urlgenerator_spec.rb +34 -0
- metadata +6 -6
- data/bin/kayakoapi +0 -42
data/README.md
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
-
# Kayakoapi
|
1
|
+
# Kayakoapi-Ruby
|
2
2
|
|
3
|
-
Basic ruby
|
4
|
-
|
5
|
-
Currently prints the generated URL to the console.
|
6
|
-
|
7
|
-
Minutely tested.
|
3
|
+
Basic ruby gem to generate API signatures compatible with the [Kayako REST API](http://wiki.kayako.com/display/DEV/Kayako+REST+API)
|
8
4
|
|
9
5
|
## Installation
|
10
6
|
|
@@ -12,9 +8,9 @@ Add this line to your application's Gemfile:
|
|
12
8
|
|
13
9
|
gem 'kayakoapi-ruby'
|
14
10
|
|
15
|
-
And then
|
11
|
+
And then:
|
16
12
|
|
17
|
-
$ bundle
|
13
|
+
$ bundle install
|
18
14
|
|
19
15
|
Or install it yourself as:
|
20
16
|
|
@@ -22,18 +18,21 @@ Or install it yourself as:
|
|
22
18
|
|
23
19
|
## Usage
|
24
20
|
|
25
|
-
|
21
|
+
require 'kayako-ruby'
|
26
22
|
|
27
|
-
|
23
|
+
generator = KayakoApi.new('http://my.kayako.helpdesk/api', 'my-application-key', 'my-application-secret')
|
28
24
|
|
29
|
-
|
25
|
+
generator.url
|
26
|
+
#=> "http://my.kayako.helpdesk/api/index.php?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"
|
30
27
|
|
31
|
-
|
28
|
+
generator.signature
|
29
|
+
#=> {:signature=>"%61%33%4F%6F%59%39%44%79%71%31%4F%6D%4D%6F%74%7A%47%44%4A%76%37%30%4F%6C%6F%48%74/%79%6D%6F%4C%70%43%77%57%52%57%41%6F%52%45%6B=", :salt=>"5265651781", :apikey=>"my-application-key"}
|
32
30
|
|
33
|
-
|
31
|
+
nb. you will need to add your own controller and action to the url.
|
34
32
|
|
35
|
-
|
33
|
+
If an error occurs, KayakoApi#url will return false.
|
36
34
|
|
35
|
+
The salt is randomly generated, but included in the querystring (as per the [Kayako REST API](http://wiki.kayako.com/display/DEV/Kayako+REST+API).
|
37
36
|
|
38
37
|
## Contributing
|
39
38
|
|
data/lib/kayakoapi-ruby.rb
CHANGED
@@ -2,22 +2,25 @@ require "kayakoapi-ruby/version"
|
|
2
2
|
require "kayakoapi-ruby/apisig"
|
3
3
|
require "kayakoapi-ruby/urlgenerator"
|
4
4
|
|
5
|
-
|
6
|
-
require 'uri'
|
5
|
+
require 'uri'
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
class KayakoApi
|
8
|
+
def initialize(base_url, app_key, app_secret)
|
9
|
+
@api_sig = Kayakoapi::APISig.new(app_key, app_secret)
|
10
|
+
@url_builder = Kayakoapi::URLGenerator.new(base_url)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
13
|
+
def url
|
14
|
+
@api_sig.new_signature.each { |key, value| @url_builder.append_to_url(key, value) }
|
15
|
+
begin
|
16
|
+
@url_builder.full_url
|
17
|
+
rescue => e
|
18
|
+
false
|
21
19
|
end
|
22
20
|
end
|
21
|
+
|
22
|
+
def signature
|
23
|
+
@api_sig.new_signature
|
24
|
+
end
|
23
25
|
end
|
26
|
+
|
@@ -1,5 +1,4 @@
|
|
1
1
|
module Kayakoapi
|
2
|
-
# Required Libraries
|
3
2
|
require 'openssl'
|
4
3
|
require 'base64'
|
5
4
|
|
@@ -10,7 +9,7 @@ module Kayakoapi
|
|
10
9
|
end
|
11
10
|
|
12
11
|
def get_salt()
|
13
|
-
|
12
|
+
rand(10000000000).to_s
|
14
13
|
end
|
15
14
|
|
16
15
|
def hash(key, salt)
|
@@ -22,11 +21,11 @@ module Kayakoapi
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def new_signature()
|
25
|
-
self.get_salt
|
26
|
-
hash = self.hash(@secret_key,
|
24
|
+
salt = self.get_salt
|
25
|
+
hash = self.hash(@secret_key, salt)
|
27
26
|
b64hash = self.b64encode hash
|
28
|
-
|
29
|
-
return { signature:
|
27
|
+
last_hash = URLGenerator::urlncode b64hash.strip
|
28
|
+
return { signature: last_hash, salt: salt, apikey: @api_key }
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -2,9 +2,12 @@ module Kayakoapi
|
|
2
2
|
require 'uri'
|
3
3
|
|
4
4
|
class URLGenerator
|
5
|
+
attr_accessor :url_root, :params
|
6
|
+
|
5
7
|
def initialize(url_root)
|
6
8
|
@url_root = url_root
|
7
9
|
@params = {}
|
10
|
+
@first_param = true
|
8
11
|
end
|
9
12
|
|
10
13
|
def append_to_url(key, value)
|
@@ -14,10 +17,15 @@ module Kayakoapi
|
|
14
17
|
def full_url
|
15
18
|
current_url = @url_root
|
16
19
|
if @params.empty?
|
17
|
-
raise
|
20
|
+
raise NoURLParameters.new(msg: "Params hash is empty while attempting to build a URL.")
|
18
21
|
else
|
19
22
|
@params.each do |key, value|
|
20
|
-
|
23
|
+
if @first_param
|
24
|
+
current_url += "?#{key}=#{value}"
|
25
|
+
@first_param = false
|
26
|
+
else
|
27
|
+
current_url += "&#{key}=#{value}"
|
28
|
+
end
|
21
29
|
end
|
22
30
|
return current_url
|
23
31
|
end
|
@@ -31,4 +39,4 @@ module Kayakoapi
|
|
31
39
|
URI.escape(string, Regexp.new("[Generating an API Signature^#{URI::PATTERN::UNRESERVED}]"))
|
32
40
|
end
|
33
41
|
end
|
34
|
-
end
|
42
|
+
end
|
data/spec/apisig_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "kayakoapi-ruby/urlgenerator"
|
3
|
+
require "kayakoapi-ruby/exceptions"
|
4
|
+
|
5
|
+
describe "URLGenerator" do
|
6
|
+
before :each do
|
7
|
+
@urlgen = Kayakoapi::URLGenerator.new("http://fake-url.com/")
|
8
|
+
@urlgen.append_to_url('one', 'valueone')
|
9
|
+
@urlgen.append_to_url('two', 'valuetwo')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should remember the url" do
|
13
|
+
@urlgen.url_root.should_not be_nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should accept new parameters" do
|
17
|
+
@urlgen.append_to_url('troled', 'pigs')
|
18
|
+
@urlgen.params.should have_key('troled')
|
19
|
+
@urlgen.params['troled'].should eq 'pigs'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should return a string when asked to create a full_url" do
|
23
|
+
@urlgen.full_url.should eq "http://fake-url.com/?one=valueone&two=valuetwo"
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should raise on failure" do
|
27
|
+
@urlgen.params = {}
|
28
|
+
expect{@urlgen.full_url}.to raise_error(Kayakoapi::NoURLParameters)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a static method for encoding urls" do
|
32
|
+
Kayakoapi::URLGenerator::urlncode('tr o%ed').should eq "%74%72%20%6F%%65%64"
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kayakoapi-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -30,8 +30,7 @@ dependencies:
|
|
30
30
|
description: Ruby Shoes app to generate Kayako API URLs.
|
31
31
|
email:
|
32
32
|
- bulletraven@gmail.com
|
33
|
-
executables:
|
34
|
-
- kayakoapi
|
33
|
+
executables: []
|
35
34
|
extensions: []
|
36
35
|
extra_rdoc_files: []
|
37
36
|
files:
|
@@ -41,7 +40,6 @@ files:
|
|
41
40
|
- LICENSE.txt
|
42
41
|
- README.md
|
43
42
|
- Rakefile
|
44
|
-
- bin/kayakoapi
|
45
43
|
- kayakoapi-ruby.gemspec
|
46
44
|
- lib/kayakoapi-ruby.rb
|
47
45
|
- lib/kayakoapi-ruby/apisig.rb
|
@@ -50,6 +48,7 @@ files:
|
|
50
48
|
- lib/kayakoapi-ruby/version.rb
|
51
49
|
- spec/apisig_spec.rb
|
52
50
|
- spec/spec_helper.rb
|
51
|
+
- spec/urlgenerator_spec.rb
|
53
52
|
homepage: https://github.com/wadtech/kayakoapi-ruby
|
54
53
|
licenses: []
|
55
54
|
post_install_message:
|
@@ -70,10 +69,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
69
|
version: '0'
|
71
70
|
requirements: []
|
72
71
|
rubyforge_project:
|
73
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.25
|
74
73
|
signing_key:
|
75
74
|
specification_version: 3
|
76
75
|
summary: Ruby Shoes app to generate Kayako Resolve API URLs.
|
77
76
|
test_files:
|
78
77
|
- spec/apisig_spec.rb
|
79
78
|
- spec/spec_helper.rb
|
79
|
+
- spec/urlgenerator_spec.rb
|
data/bin/kayakoapi
DELETED
@@ -1,42 +0,0 @@
|
|
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
|