keima 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/keima.gemspec +22 -0
- data/lib/keima.rb +7 -0
- data/lib/keima/client.rb +38 -0
- data/lib/keima/version.rb +3 -0
- data/spec/keima/client_spec.rb +21 -0
- data/spec/spec_helper.rb +1 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 codefirst.org
|
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,31 @@
|
|
1
|
+
# Keima Ruby API
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
gem 'keima'
|
8
|
+
|
9
|
+
Or install it yourself as:
|
10
|
+
|
11
|
+
$ gem install keima
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
require 'rubygems'
|
16
|
+
require 'keima'
|
17
|
+
|
18
|
+
client = Keima::Client.new("keima base url", "api key")
|
19
|
+
client.publish("channel name", "event name", {:message => "test"})
|
20
|
+
|
21
|
+
## Build
|
22
|
+
|
23
|
+
$ bundle exec rake build
|
24
|
+
|
25
|
+
## Test
|
26
|
+
|
27
|
+
$ bundle exec rspec
|
28
|
+
|
29
|
+
## License
|
30
|
+
|
31
|
+
See LICENSE file
|
data/Rakefile
ADDED
data/keima.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require File.expand_path('../lib/keima/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.authors = ["suer"]
|
7
|
+
gem.email = ["suetsugu.r@gmail.com"]
|
8
|
+
gem.description = %q{a keima ruby client}
|
9
|
+
gem.summary = %q{a keima ruby client}
|
10
|
+
gem.homepage = ""
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.name = "keima"
|
16
|
+
gem.require_paths = ["lib"]
|
17
|
+
gem.version = Keima::VERSION
|
18
|
+
|
19
|
+
gem.add_dependency "json"
|
20
|
+
gem.add_development_dependency "rake"
|
21
|
+
gem.add_development_dependency "rspec"
|
22
|
+
end
|
data/lib/keima.rb
ADDED
data/lib/keima/client.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
module Keima
|
3
|
+
class Client
|
4
|
+
def initialize(base_url, appkey)
|
5
|
+
@base_url = base_url
|
6
|
+
@appkey = appkey
|
7
|
+
end
|
8
|
+
|
9
|
+
def publish_url
|
10
|
+
@base_url + "/publish/" + @appkey
|
11
|
+
end
|
12
|
+
|
13
|
+
def jsFiles
|
14
|
+
[ @base_url + '/socket.io/socket.io.js',
|
15
|
+
@base_url + '/javascripts/keima.js' ]
|
16
|
+
end
|
17
|
+
|
18
|
+
def publish(channel, name, data)
|
19
|
+
post(publish_url, {
|
20
|
+
:channel => channel,
|
21
|
+
:name => name,
|
22
|
+
:data => data.to_json
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
def post(url, params)
|
27
|
+
uri = URI.parse(url)
|
28
|
+
body = params.map{|key,value| "#{escape(key.to_s)}=#{escape(value)}" }.join('&')
|
29
|
+
Net::HTTP.start(uri.host, uri.port) do |http|
|
30
|
+
http.post(uri.path, body)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def escape(str)
|
35
|
+
URI.escape(URI.escape(str), /[&+]/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
+
|
3
|
+
describe Keima::Client do
|
4
|
+
|
5
|
+
base_url = 'http://localhost:3001'
|
6
|
+
|
7
|
+
context "when base url is #{base_url}" do
|
8
|
+
before { @client = Keima::Client.new(base_url, '503b7d29e1f85c9632000001') }
|
9
|
+
context 'post' do
|
10
|
+
subject { @client }
|
11
|
+
its(:publish_url) { should == 'http://localhost:3001/publish/503b7d29e1f85c9632000001' }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'js files' do
|
15
|
+
subject { @client }
|
16
|
+
its(:jsFiles) {
|
17
|
+
should == ['http://localhost:3001/socket.io/socket.io.js', 'http://localhost:3001/javascripts/keima.js']
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../lib/keima.rb'
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: keima
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- suer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-12 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: :runtime
|
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: rake
|
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
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: a keima ruby client
|
63
|
+
email:
|
64
|
+
- suetsugu.r@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- keima.gemspec
|
75
|
+
- lib/keima.rb
|
76
|
+
- lib/keima/client.rb
|
77
|
+
- lib/keima/version.rb
|
78
|
+
- spec/keima/client_spec.rb
|
79
|
+
- spec/spec_helper.rb
|
80
|
+
homepage: ''
|
81
|
+
licenses: []
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
hash: 506620441674377152
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: 506620441674377152
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.24
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: a keima ruby client
|
110
|
+
test_files:
|
111
|
+
- spec/keima/client_spec.rb
|
112
|
+
- spec/spec_helper.rb
|