haruna 0.0.1.2 → 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/README.md +42 -14
- data/haruna.gemspec +1 -0
- data/lib/haruna/api.rb +29 -19
- data/lib/haruna/client.rb +5 -5
- data/lib/haruna/version.rb +1 -1
- data/spec/api_spec.rb +27 -7
- data/spec/client_spec.rb +14 -9
- data/spec/spec_helper.rb +16 -4
- metadata +18 -2
data/README.md
CHANGED
@@ -18,25 +18,53 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
```ruby
|
22
|
+
client = Haruna::Client.new(token, end_point)
|
22
23
|
|
23
|
-
|
24
|
-
|
24
|
+
# start a mission
|
25
|
+
client.req_mission_start(deck_id, mission_id)
|
25
26
|
|
26
|
-
|
27
|
-
|
27
|
+
# obtain mission result
|
28
|
+
client.req_mission_result(deck_id)
|
28
29
|
|
29
|
-
|
30
|
-
|
30
|
+
# refill fuel & bullets
|
31
|
+
client.req_hokyu_charge(kind, ship_id_arr)
|
32
|
+
```
|
31
33
|
|
32
|
-
###
|
34
|
+
### Parameters
|
35
|
+
|
36
|
+
| Param | Description | Sample | Constraint |
|
37
|
+
| ------------- | -------------- | ------------------------------------------ | ---------- |
|
38
|
+
| token | Your API token | "835d2a8f2ca5fea2463248cc6910af96880fc29e" | |
|
39
|
+
| end_point | API endpoint | "http://125.6.189.215" | |
|
40
|
+
| ship_id | Ship's id | 35 | 1 |
|
41
|
+
| deck_id | Deck's id | 3 | 1 ~ 4 |
|
42
|
+
| kind | Refill mode - 1: fuel, 2: bullets, 3: fuel + bullets | 3 | 1 ~ 3 |
|
43
|
+
|
44
|
+
### Configuration
|
45
|
+
|
46
|
+
You can configure a `Haruna::Client` by passing it options when it's initialized.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
# specify proxy server
|
50
|
+
proxy_client = Haruna::Client.new(token, end_point, proxy: "http://127.0.0.1:8888")
|
51
|
+
|
52
|
+
# you can modify HTTP request header
|
53
|
+
client = Haruna::Client.new(token, end_point, user_agent: "My User Agent", accept_enc: "gzip")
|
54
|
+
# or you can rewrite the settings after initialization
|
55
|
+
client.user_agent = "Foo Bar"
|
56
|
+
```
|
57
|
+
|
58
|
+
| Option | Description | Default |
|
59
|
+
| -------------- | ----------------- | ------------------------------------ |
|
60
|
+
| :proxy | Proxy server URL | nil |
|
61
|
+
| :api_ver | API version | 1 |
|
62
|
+
| :user_agent | User Agent | "Mozilla/5.0 (M..." |
|
63
|
+
| :referer | Referer | "/kcs/port.swf?version=1.5.5" |
|
64
|
+
| :accept_enc | Accept-Encoding | "gzip,deflate,sdch" |
|
65
|
+
| :accept_lang | Accept-Encoding | "ja,en-US;q=0.8,en;q=0.6" |
|
66
|
+
| :content_type | Content-Type | "application/x-www-form-urlencoded" |
|
33
67
|
|
34
|
-
| Param | Description | Constraint |
|
35
|
-
| ------------- | -------------- | ---------- |
|
36
|
-
| token | Your API token | |
|
37
|
-
| ship_id | Ship's id | 1 ~ |
|
38
|
-
| deck_id | Deck's id | 1 ~ 4 |
|
39
|
-
| kind | Refill mode - 1: oil, 2: bullets, 3: oil + bullets | 1 ~ 3 |
|
40
68
|
|
41
69
|
|
42
70
|
## Disclaimer
|
data/haruna.gemspec
CHANGED
data/lib/haruna/api.rb
CHANGED
@@ -1,42 +1,52 @@
|
|
1
1
|
module Haruna
|
2
2
|
|
3
3
|
class API
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
attr_writer :conn # for testing, not really need to rewrite this
|
5
|
+
attr_accessor :proxy, :api_ver, :user_agent, :referer, :accept_enc, :accept_lang, :content_type
|
6
|
+
|
7
|
+
DEFAULT_OPTS = {
|
8
|
+
proxy: nil,
|
9
|
+
api_ver: 1,
|
10
|
+
user_agent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36',
|
11
|
+
referer: '/kcs/port.swf?version=1.5.5', # 'http://125.6.189.215/kcs/port.swf?version=1.5.5'
|
12
|
+
accept_enc: 'gzip,deflate,sdch',
|
13
|
+
accept_lang: 'ja,en-US;q=0.8,en;q=0.6',
|
14
|
+
content_type: 'application/x-www-form-urlencoded'
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(token, end_point, opts={})
|
14
18
|
require 'faraday'
|
15
19
|
@token = token
|
20
|
+
@end_point = end_point
|
21
|
+
|
22
|
+
self.setup(opts || {})
|
16
23
|
|
17
|
-
@conn = Faraday.new(:url =>
|
24
|
+
@conn = Faraday.new(:url => @end_point, :proxy => @proxy) do |faraday|
|
18
25
|
faraday.request :url_encoded
|
19
26
|
# faraday.response :logger
|
20
27
|
faraday.adapter Faraday.default_adapter
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
24
|
-
attr_writer :conn # for testing, not really need to rewrite
|
25
|
-
|
26
31
|
def call(action, target, param={})
|
27
32
|
@conn.post do |req|
|
28
33
|
req.url "/kcsapi/#{action}/#{target}"
|
29
|
-
req.headers['User-Agent'] =
|
30
|
-
req.headers['Referer'] =
|
31
|
-
req.headers['Accept-Encoding'] =
|
32
|
-
req.headers['Accept-Language'] =
|
33
|
-
req.headers['Content-Type'] =
|
34
|
+
req.headers['User-Agent'] = @user_agent
|
35
|
+
req.headers['Referer'] = "#{@end_point}#{@referer}"
|
36
|
+
req.headers['Accept-Encoding'] = @accept_enc
|
37
|
+
req.headers['Accept-Language'] = @accept_lang
|
38
|
+
req.headers['Content-Type'] = @content_type
|
34
39
|
req.body = setup_param(param)
|
35
40
|
end
|
36
41
|
end
|
37
42
|
|
38
43
|
def setup_param(param)
|
39
|
-
param.merge(api_verno:
|
44
|
+
param.merge(api_verno: @api_ver, api_token: @token)
|
45
|
+
end
|
46
|
+
|
47
|
+
def setup(opts)
|
48
|
+
DEFAULT_OPTS.merge(opts).each { |key, value| instance_variable_set("@#{key}", value) }
|
49
|
+
self
|
40
50
|
end
|
41
51
|
|
42
52
|
end
|
data/lib/haruna/client.rb
CHANGED
@@ -2,8 +2,8 @@ module Haruna
|
|
2
2
|
|
3
3
|
class Client < API
|
4
4
|
|
5
|
-
def initialize(token,
|
6
|
-
super(token,
|
5
|
+
def initialize(token, end_point, opts={})
|
6
|
+
super(token, end_point, opts)
|
7
7
|
end
|
8
8
|
|
9
9
|
def req_mission_start(deck_id, mission_id)
|
@@ -22,9 +22,9 @@ module Haruna
|
|
22
22
|
end
|
23
23
|
|
24
24
|
# kind
|
25
|
-
# 1:
|
26
|
-
# 2: bullet
|
27
|
-
# 3:
|
25
|
+
# 1: fuel
|
26
|
+
# 2: bullet
|
27
|
+
# 3: fuel + bullet
|
28
28
|
def req_hokyu_charge(kind, ship_id_arr)
|
29
29
|
validate_supply_kind(kind)
|
30
30
|
validate_ship_ids(ship_id_arr)
|
data/lib/haruna/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -2,24 +2,44 @@
|
|
2
2
|
require File.expand_path(File.join('./', 'spec_helper'), File.dirname(__FILE__))
|
3
3
|
|
4
4
|
describe Haruna::API do
|
5
|
-
|
5
|
+
before do
|
6
|
+
@token = "abcdefg"
|
7
|
+
@end_point = "http://125.6.189.215"
|
8
|
+
end
|
6
9
|
|
7
|
-
|
10
|
+
describe "#new" do
|
11
|
+
context "when token & end_point are empty" do
|
8
12
|
it "should raise error" do
|
9
13
|
expect{ Haruna::API.new }.to raise_error(ArgumentError)
|
10
14
|
end
|
11
15
|
end
|
12
16
|
|
13
|
-
context "when token
|
14
|
-
subject { Haruna::API.new(
|
17
|
+
context "when token & end_point are specified" do
|
18
|
+
subject { Haruna::API.new(@token, @end_point) }
|
15
19
|
it { should be_an_instance_of Haruna::API }
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
23
|
+
describe "#setup_param" do
|
24
|
+
subject { Haruna::API.new(@token, @end_point, opts) }
|
25
|
+
context "when opt is empty" do
|
26
|
+
let(:opts) { nil }
|
27
|
+
describe "return value" do
|
28
|
+
it { should be_an_instance_of Haruna::API }
|
29
|
+
end
|
30
|
+
describe "default setting" do
|
31
|
+
its(:api_ver) { should eq 1 }
|
32
|
+
its(:accept_enc) { should eq "gzip,deflate,sdch" }
|
33
|
+
its(:accept_lang) { should eq "ja,en-US;q=0.8,en;q=0.6" }
|
34
|
+
its(:content_type) { should eq "application/x-www-form-urlencoded" }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
19
39
|
describe "#setup_param" do
|
20
40
|
before do
|
21
|
-
@token =
|
22
|
-
@api = Haruna::API.new(@token)
|
41
|
+
@token = @token
|
42
|
+
@api = Haruna::API.new(@token, @end_point)
|
23
43
|
end
|
24
44
|
|
25
45
|
subject { @api.setup_param(param) }
|
@@ -42,7 +62,7 @@ describe Haruna::API do
|
|
42
62
|
|
43
63
|
describe "#call" do
|
44
64
|
before do
|
45
|
-
@api = Haruna::API.new(
|
65
|
+
@api = Haruna::API.new(@token, @end_point)
|
46
66
|
@api.conn = create_stub_connection # overwrite faraday adapter
|
47
67
|
end
|
48
68
|
|
data/spec/client_spec.rb
CHANGED
@@ -3,22 +3,27 @@ require File.expand_path(File.join('./', 'spec_helper'), File.dirname(__FILE__))
|
|
3
3
|
|
4
4
|
describe Haruna::Client do
|
5
5
|
|
6
|
+
before do
|
7
|
+
@token = "abcdefg"
|
8
|
+
@end_point = "http://125.6.189.215"
|
9
|
+
end
|
10
|
+
|
6
11
|
describe "#new" do
|
7
|
-
context "when token
|
12
|
+
context "when token & end_point are empty" do
|
8
13
|
it "should raise error" do
|
9
14
|
expect{ Haruna::Client.new }.to raise_error(ArgumentError)
|
10
15
|
end
|
11
16
|
end
|
12
17
|
|
13
|
-
context "when token
|
14
|
-
subject { Haruna::Client.new(
|
18
|
+
context "when token & end_point are NOT empty" do
|
19
|
+
subject { Haruna::Client.new(@token, @end_point) }
|
15
20
|
it { should be_an_instance_of Haruna::Client }
|
16
21
|
end
|
17
22
|
end
|
18
23
|
|
19
24
|
describe "client commands" do
|
20
25
|
before do
|
21
|
-
@client = Haruna::Client.new(
|
26
|
+
@client = Haruna::Client.new(@token, @end_point)
|
22
27
|
@client.conn = create_stub_connection # overwrite faraday adapter
|
23
28
|
end
|
24
29
|
|
@@ -30,7 +35,7 @@ describe Haruna::Client do
|
|
30
35
|
end
|
31
36
|
context "w/ two parameters" do
|
32
37
|
subject { @client.req_mission_start(1, 1) }
|
33
|
-
its(:body) { should
|
38
|
+
its(:body) { should start_with "svdata" }
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
@@ -42,7 +47,7 @@ describe Haruna::Client do
|
|
42
47
|
end
|
43
48
|
context "w/ two parameters" do
|
44
49
|
subject { @client.req_mission_result(1) }
|
45
|
-
its(:body) { should
|
50
|
+
its(:body) { should start_with "svdata" }
|
46
51
|
end
|
47
52
|
end
|
48
53
|
|
@@ -54,14 +59,14 @@ describe Haruna::Client do
|
|
54
59
|
end
|
55
60
|
context "w/ two parameters" do
|
56
61
|
subject { @client.req_hokyu_charge(1, [1,2,3]) }
|
57
|
-
its(:body) { should
|
62
|
+
its(:body) { should start_with "svdata" }
|
58
63
|
end
|
59
64
|
end
|
60
65
|
|
61
66
|
describe "#get_member_deck_port" do
|
62
67
|
context "w/o parameters" do
|
63
68
|
subject { @client.get_member_deck_port }
|
64
|
-
its(:body) { should
|
69
|
+
its(:body) { should start_with "svdata" }
|
65
70
|
end
|
66
71
|
context "w/ a parameter" do
|
67
72
|
it "should raise an error" do
|
@@ -74,7 +79,7 @@ describe Haruna::Client do
|
|
74
79
|
|
75
80
|
describe "validators" do
|
76
81
|
before do
|
77
|
-
@client = Haruna::Client.new(
|
82
|
+
@client = Haruna::Client.new(@token, @end_point)
|
78
83
|
end
|
79
84
|
|
80
85
|
describe "#validate_deck_id" do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,18 +1,30 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
3
|
require 'haruna'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
def create_stub_connection
|
7
|
+
|
8
|
+
resp_headers = {"date"=>"Sat, 21 Dec 2013 04:11:07 GMT", "server"=>"Apache", "x-powered-by"=>"PHP/5.3.3", "content-length"=>"149", "content-type"=>"text/plain", "proxy-connection"=>"Close"}
|
9
|
+
|
6
10
|
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
7
11
|
# stub.post(url) { [status_code, response_header, response_body] }
|
8
12
|
stub.post('/kcsapi/get_seafood/tamago') {[ 200, {}, 'egg' ]}
|
9
13
|
stub.post('/kcsapi/get_seafood/ebi') {[ 200, {}, 'shrimp' ]}
|
10
14
|
stub.post('/kcsapi/get_seafood/uni') {[ 200, {}, 'urchin' ]}
|
11
15
|
|
12
|
-
stub.post(
|
13
|
-
stub.post('/kcsapi/api_req_mission/
|
14
|
-
|
15
|
-
|
16
|
+
# stub.post(url) { [status_code, response_header, response_body] }
|
17
|
+
stub.post('/kcsapi/api_req_mission/start') {[ 200, resp_headers,
|
18
|
+
"svdata={\"api_result\":1,\"api_result_msg\":\"\\u6210\\u529f\",\"api_data\":{\"api_complatetime\":1387604467275,\"api_complatetime_str\":\"2013-12-21 14:41:07\"}}" ]} # BOM: \xEF\xBB\xBF
|
19
|
+
|
20
|
+
stub.post('/kcsapi/api_req_mission/result') {[ 200, resp_headers,
|
21
|
+
"svdata={\"api_result\":1,\"api_result_msg\":\"\\u6210\\u529f\",\"api_data\":{\"api_ship_id\":[-1,54,78,71,50],\"api_clear_result\":1,\"api_get_exp\":20,\"api_member_lv\":28,\"api_member_exp\":40216,\"api_get_ship_exp\":[22,15,15,15],\"api_get_exp_lvup\":[[2157,2800],[1730,2100],[2230,2800],[1555,2100]],\"api_maparea_name\":\"\\u93ae\\u5b88\\u5e9c\\u6d77\\u57df\",\"api_detail\":\"\\u5916\\u6d77\\u307e\\u3067\\u8db3\\u3092\\u5ef6\\u3070\\u3057\\u3001\\u8266\\u968a\\u306e\\u7df4\\u5ea6\\u3092\\u9ad8\\u3081\\u3088\\u3046\\uff01\",\"api_quest_name\":\"\\u9577\\u8ddd\\u96e2\\u7df4\\u7fd2\\u822a\\u6d77\",\"api_quest_level\":1,\"api_get_material\":[0,100,30,0],\"api_useitem_flag\":[1,0],\"api_get_item1\":{\"api_useitem_id\":-1,\"api_useitem_name\":null,\"api_useitem_count\":1}}}" ]}
|
22
|
+
|
23
|
+
stub.post('/kcsapi/api_req_hokyu/charge') {[ 200, resp_headers,
|
24
|
+
"svdata={\"api_result\":1,\"api_result_msg\":\"\\u6210\\u529f\",\"api_data\":{\"api_ship\":[{\"api_id\":54,\"api_fuel\":15,\"api_bull\":15,\"api_onslot\":[0,0,0,0,0]},{\"api_id\":78,\"api_fuel\":15,\"api_bull\":15,\"api_onslot\":[0,0,0,0,0]},{\"api_id\":71,\"api_fuel\":15,\"api_bull\":15,\"api_onslot\":[0,0,0,0,0]},{\"api_id\":50,\"api_fuel\":15,\"api_bull\":15,\"api_onslot\":[0,0,0,0,0]}],\"api_material\":[2938,5864,4151,3933],\"api_use_bou\":0}}" ]}
|
25
|
+
|
26
|
+
stub.post('/kcsapi/api_get_member/deck_port') {[ 200, resp_headers,
|
27
|
+
"svdata={\"api_result\":1,\"api_result_msg\":\"\\u6210\\u529f\",\"api_data\":[{\"api_member_id\":15010331,\"api_id\":1,\"api_name\":\"First\",\"api_name_id\":\"\",\"api_mission\":[0,0,0,0],\"api_flagship\":\"0\",\"api_ship\":[109,156,177,31,194,30]},{\"api_member_id\":15010331,\"api_id\":2,\"api_name\":\"Second\",\"api_name_id\":\"\",\"api_mission\":[1,5,1387598754473,0],\"api_flagship\":\"0\",\"api_ship\":[15,66,57,83,-1,-1]},{\"api_member_id\":15010331,\"api_id\":3,\"api_name\":\"Third\",\"api_name_id\":\"\",\"api_mission\":[1,2,1387595310643,0],\"api_flagship\":\"0\",\"api_ship\":[54,78,71,50,-1,-1]}]}" ]}
|
16
28
|
|
17
29
|
end
|
18
30
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: haruna
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
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-
|
12
|
+
date: 2013-12-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: Write a gem description
|
79
95
|
email:
|
80
96
|
- kakipo@gmail.com
|