slash7 0.0.1
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 +41 -0
- data/Rakefile +2 -0
- data/lib/slash7.rb +5 -0
- data/lib/slash7/client.rb +42 -0
- data/lib/slash7/version.rb +3 -0
- data/slash7.gemspec +21 -0
- data/spec/slash7/client_spec.rb +48 -0
- data/spec/spec_helper.rb +11 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 pLucky, Inc.
|
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,41 @@
|
|
1
|
+
# Slash7
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'slash7'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install slash7
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
````
|
22
|
+
require 'slash7'
|
23
|
+
client = Slash7::Client.new('[YOUR TRACKING CODE]')
|
24
|
+
# Build your own event
|
25
|
+
# See https://p-lucky.atlassian.net/wiki/display/PUB/Event+log+format for the format.
|
26
|
+
event = {
|
27
|
+
'_event_name' => 'attack',
|
28
|
+
'_app_user_id' => 'user100123',
|
29
|
+
'_event_params' => {'weapon' => 'long sword'},
|
30
|
+
'lv' => 21
|
31
|
+
}
|
32
|
+
client.send_data(event)
|
33
|
+
````
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/slash7.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'json'
|
3
|
+
require 'base64'
|
4
|
+
require 'net/http'
|
5
|
+
|
6
|
+
module Slash7
|
7
|
+
class Client
|
8
|
+
|
9
|
+
SERVER = 'tracker.slash-7.com'
|
10
|
+
|
11
|
+
# Initialize SLASH-7 client
|
12
|
+
# @param [String] tracing_code SLASH-7 tracking code for your project
|
13
|
+
# @param [Hash] options Options
|
14
|
+
def initialize(tracing_code, options = {})
|
15
|
+
@tracing_code = tracing_code
|
16
|
+
@options = options
|
17
|
+
end
|
18
|
+
|
19
|
+
# Send data to SLASH-7.
|
20
|
+
# See https://p-lucky.atlassian.net/wiki/display/PUB/Event+log+format for the format.
|
21
|
+
# @param [Hash] data
|
22
|
+
def send_data(data)
|
23
|
+
Net::HTTP.post_form(URI.parse(endpoint_url), {'data' => self.class.encode(data)})
|
24
|
+
end
|
25
|
+
|
26
|
+
def endpoint_url
|
27
|
+
"http://#{server}/track/#@tracing_code"
|
28
|
+
end
|
29
|
+
|
30
|
+
def server
|
31
|
+
@options[:server] || SERVER
|
32
|
+
end
|
33
|
+
|
34
|
+
class << self
|
35
|
+
# @param [Hash] data
|
36
|
+
def encode(data)
|
37
|
+
Base64.encode64(data.to_json)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
data/slash7.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/slash7/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["KAWACHI Takashi"]
|
6
|
+
gem.email = ["kawachi@p-lucky.net"]
|
7
|
+
gem.description = %q{SLASH-7 client library}
|
8
|
+
gem.summary = %q{SLASH-7 client library for Ruby}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "slash7"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Slash7::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency('rspec')
|
19
|
+
gem.add_development_dependency('rake')
|
20
|
+
gem.add_development_dependency('rr')
|
21
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Slash7
|
4
|
+
describe Client do
|
5
|
+
let (:client) { Client.new('CODE') }
|
6
|
+
let (:event) do
|
7
|
+
{
|
8
|
+
'_event_name' => 'attack',
|
9
|
+
'_app_user_id' => 'user100123',
|
10
|
+
'_event_params' => {'weapon' => 'long sword'},
|
11
|
+
'lv' => 21
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#send_data' do
|
16
|
+
it do
|
17
|
+
mock(Net::HTTP).post_form.with_any_args { 1 }
|
18
|
+
client.send_data(event)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#endpoint_url' do
|
23
|
+
it 'returns a correct endpoint' do
|
24
|
+
client.endpoint_url.should == 'http://tracker.slash-7.com/track/CODE'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#server' do
|
29
|
+
it 'returns default server' do
|
30
|
+
client.server.should == 'tracker.slash-7.com'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'returns customized server' do
|
34
|
+
client = Client.new('CODE', server: 'example.com')
|
35
|
+
client.server.should == 'example.com'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '.encode' do
|
40
|
+
it 'can be decoded' do
|
41
|
+
encoded = Client.encode(event)
|
42
|
+
base64_decoded = Base64.decode64(encoded)
|
43
|
+
hash = JSON.parse(base64_decoded)
|
44
|
+
hash.should == event
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib/')
|
2
|
+
require 'slash7'
|
3
|
+
require 'base64'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.mock_with :rr
|
9
|
+
# or if that doesn't work due to a version incompatibility
|
10
|
+
# config.mock_with RR::Adapters::Rspec
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slash7
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- KAWACHI Takashi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-15 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: '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: 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: rr
|
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: SLASH-7 client library
|
63
|
+
email:
|
64
|
+
- kawachi@p-lucky.net
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- lib/slash7.rb
|
75
|
+
- lib/slash7/client.rb
|
76
|
+
- lib/slash7/version.rb
|
77
|
+
- slash7.gemspec
|
78
|
+
- spec/slash7/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: 2262735121597329643
|
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: 2262735121597329643
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 1.8.24
|
107
|
+
signing_key:
|
108
|
+
specification_version: 3
|
109
|
+
summary: SLASH-7 client library for Ruby
|
110
|
+
test_files:
|
111
|
+
- spec/slash7/client_spec.rb
|
112
|
+
- spec/spec_helper.rb
|