libgss 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTdkNjg4OGZmYTAzNDNjN2VjNTM4Mjg0NzIzOGU4MTMzODdjYzgxZQ==
4
+ OTY1Y2NkY2JlMzViNGQ4YzczYTQyMmY1MThiZDFhZDQzOGMwMmY3Nw==
5
5
  data.tar.gz: !binary |-
6
- OWY0MWFkMDNmMDEzZTlmMzY0NWI5NzJmMzRhZjU1ZmU3NWFkNDE2OQ==
6
+ MzY4M2Q0N2Y3NjRhMmMyYmJjNjM3MzIxNTdhMzY2ZGU0NmViNGQ4NA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDcyMzY2YWI4NDVmZWJjZTIzZTE2MTEzMWQyZDBmZTU2Mjk1OWQyZWJiYTdl
10
- Yjc1MDljNzhmODkzYjUxYmVlYTlmMjFmOGI3MjIxYmFkZDQwNzI2MTQwZmFi
11
- Zjk2MmM4NGQyZTk4MGE3NWZkNjVlNjU4OTlhMDlhMWJkYTE2YzI=
9
+ MzAxOWExYTUwYjMwOWNhOWQ0ZTVlMjIyMDQyOGI5Y2ExN2E2MzlmYjFmNzdi
10
+ MmU3NDgwYTdkZjIwOTJkODc0YTkxM2FmYTIyNGY5OWE1N2RmNWYzNTkyODJj
11
+ ZGVjNGE0ZDI3N2RhOTI0NzdmNjVkMzE3MmE2Y2QwNGVjZDVlZDg=
12
12
  data.tar.gz: !binary |-
13
- NTA5M2U4NWQ2ZDlhODI4ZTUyZjQyNzgyZGNmNzYyMGQ0ZWE1NmNhNzU5OTk5
14
- M2M2MjM1MTljZmY2MGFkYzJkNGY2ZGYxNTllNjUxZjMxOWJjNzIwMjhkZWYz
15
- NTlhZmU3NThmNDIwYmY3ZWY5MDQ4MWRiNWFhZDFkMGFkZDA4MmM=
13
+ NjczMGQzZDI3ZTkwZDkyMzkwMGZjOWRjNTBlNDRkNGJkNDRjNzliNGJmZDI2
14
+ NTYyYmM2NzRiMTc0YWM2NGY0Mzc1MjVhOWQwZDAzOTQ5NzNlZTYwMjY1ZTRl
15
+ NDI1NjYwNjA4MDUzZjFiOTJjNGRkOWVmZWNiMTljYzU3YzdlNGE=
data/.gitmodules ADDED
@@ -0,0 +1,3 @@
1
+ [submodule "fontana_sample"]
2
+ path = fontana_sample
3
+ url = git@github.com:groovenauts/fontana_sample.git
data/Rakefile CHANGED
@@ -6,3 +6,43 @@ RSpec::Core::RakeTask.new(:spec)
6
6
 
7
7
  ENV['DEFAULT_HTTP_PORT'] ||= '3000'
8
8
  ENV['DEFAULT_HTTPS_PORT'] ||= '3001'
9
+
10
+ require 'fileutils'
11
+
12
+ def system!(cmd)
13
+ puts "now executing: #{cmd}"
14
+ IO.popen("#{cmd} 2>&1") do |io|
15
+ while line = io.gets
16
+ puts line
17
+ end
18
+ end
19
+
20
+ if $?.exitstatus != 0
21
+ exit(1)
22
+ end
23
+ end
24
+
25
+ desc "test with fontana-LibgssTest"
26
+ task :test do
27
+ fileutils = FileUtils::Verbose
28
+ __dir__ = File.expand_path("..", __FILE__)
29
+ sample_dir = File.join(__dir__, "fontana_sample")
30
+
31
+ if Dir["#{sample_dir}/*"].empty?
32
+ raise "#{sample_dir} is empty. You have to do `git submodule update --init` before `rake test`"
33
+ end
34
+
35
+ fileutils.chdir(sample_dir){ system!("rake vendor:fontana:reset servers:start") }
36
+ begin
37
+ fileutils.chdir(__dir__) do
38
+ Rake::Task["spec"].execute
39
+ end
40
+ ensure
41
+ fileutils.chdir(sample_dir){ system!("rake servers:stop") }
42
+ end
43
+
44
+ # 最後の子プロセスの終了ステータスで終了します
45
+ exit($?.exitstatus || 1)
46
+ end
47
+
48
+ task :default => :test
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ # http://doc.ruby-lang.org/ja/1.9.3/library/optparse.html
5
+ # http://qiita.com/torshinor/items/499beaba89eb09df80d5
6
+ require 'optparse'
7
+
8
+ url = ARGV.detect{|s| s !~ /\A\-/}
9
+ ARGV.delete(url)
10
+
11
+ default_options = {
12
+ "platform" => "fontana"
13
+ }
14
+ banner = "%s URL [options]" % File.basename(__FILE__)
15
+ parser = OptionParser.new(banner) do |opt|
16
+ opt.on '-i', '--player-id PLAYER_ID'
17
+ opt.on '-p', "--platform #{default_options[:platform]}"
18
+ opt.on '-c', '--consumer-secret CONSUMER_SECRET'
19
+ opt.on '-a', '--app-garden-file PATH_TO_APP_GARDEN_FILE'
20
+ opt.on '-D', '--ssl-disabled'
21
+ opt.on '-I', '--ignore-signature-key'
22
+ end
23
+
24
+ unless url
25
+ puts parser.help
26
+ exit(1)
27
+ end
28
+
29
+ options = default_options.merge(parser.getopts(ARGV))
30
+ options = options.each_with_object({}){|(k,v), d| d[k.gsub(/-/, '_').to_sym] = v}
31
+
32
+ $LOAD_PATH << File.expand_path("../../lib")
33
+ require 'libgss'
34
+
35
+ if app_garden_path = options.delete(:app_garden_file)
36
+ Fontana = Libgss::Fontana # ERBを展開する際にFontana.envなどが指定されていた場合に期待する動作をするように別名で定義します。
37
+ require 'tengine/support/yaml_with_erb'
38
+ c = YAML.load_file(app_garden_path)
39
+ options[:platform] = (c["platform"] ? c["platform"]["name"] : nil) || "fontana"
40
+ options[:consumer_secret] = c["consumer_secret"]
41
+ end
42
+
43
+ begin
44
+ network = Libgss::Network.new(url, options)
45
+ options = options.dup
46
+ options[:consumer_secret] = "<<MASKED>>" if options[:consumer_secret]
47
+ puts "login on #{url} with #{options.inspect}"
48
+ unless network.login
49
+ puts "\e[31mLogin FAILURE!\e[0m"
50
+ exit!(1)
51
+ end
52
+
53
+ puts "Login success"
54
+ puts "player_id: #{network.player_id}"
55
+
56
+ req = network.new_action_request
57
+ req.server_time
58
+ req.send_request
59
+
60
+ res = req.outputs.first
61
+ raise "req.outputs is empty: #{req.outputs}" unless res
62
+
63
+ puts "server_time: " << Time.at(res["result"]).iso8601
64
+
65
+ puts "\e[32mSUCCESS!!\e[0m"
66
+ rescue => e
67
+ puts "\e[31m[#{e.class}] #{e.message}\e[0m\n " << e.backtrace.join("\n ")
68
+ end
data/lib/libgss.rb CHANGED
@@ -9,6 +9,7 @@ module Libgss
9
9
  autoload :HttpClientWithSignatureKey, "libgss/http_client_with_signature_key"
10
10
 
11
11
  autoload :AssetRequest , "libgss/asset_request"
12
+ autoload :Fontana , "libgss/fontana"
12
13
 
13
14
  class << self
14
15
  attr_accessor :use_oauth_gem
@@ -8,6 +8,9 @@ module Libgss
8
8
 
9
9
  class ActionRequest
10
10
 
11
+ class Error < StandardError
12
+ end
13
+
11
14
  STATUS_PREPARING = 0
12
15
  STATUS_SENDING = 1
13
16
  STATUS_WAITING = 2
@@ -49,10 +52,16 @@ module Libgss
49
52
  # アクション群を実行するために実際にHTTPリクエストを送信します。
50
53
  def send_request(&callback)
51
54
  res = @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json)
55
+ case res.code.to_i
56
+ when 200..299 then # OK
57
+ else
58
+ raise Error, "failed to send action request: [#{res.code}] #{res.body}"
59
+ end
52
60
  r = JSON.parse(res.body)
53
61
  # puts res.body
54
62
  @outputs = Outputs.new(r["outputs"])
55
63
  callback.call(@outputs) if callback
64
+ @outputs
56
65
  end
57
66
 
58
67
  # 条件に該当するデータを取得
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'libgss'
3
+
4
+ module Libgss
5
+ module Fontana
6
+
7
+ class << self
8
+ # これは fontanaの Fontana.env と同じ動きをすることが期待されています。
9
+ # https://github.com/tengine/fontana/blob/master/config/application.rb#L24
10
+ def env
11
+ @env ||= (ENV["FONTANA_ENV"] || "DEVELOPMENT").to_sym
12
+ end
13
+ end
14
+
15
+ end
16
+ end
@@ -45,7 +45,8 @@ module Libgss
45
45
  @ssl_base_url = build_https_url(uri)
46
46
  end
47
47
  @ssl_base_url = @base_url if @ssl_disabled
48
- @platform = "fontana"
48
+ @platform = options[:platform] || "fontana"
49
+ @player_id = options[:player_id]
49
50
 
50
51
  @consumer_secret = options[:consumer_secret] || ENV["CONSUMER_SECRET"]
51
52
  @ignore_signature_key = !!options[:ignore_signature_key]
@@ -1,3 +1,3 @@
1
1
  module Libgss
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -114,7 +114,7 @@ describe Libgss::Network do
114
114
  end
115
115
 
116
116
  it "isn't too long" do
117
- network.inspect.length.should < 200
117
+ network.inspect.length.should < 300
118
118
  end
119
119
  end
120
120
 
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'libgss'
3
+ require 'tengine/support/yaml_with_erb'
3
4
 
4
5
  # see https://github.com/tengine/fontana/pull/3
5
6
  require 'httpclient'
@@ -10,8 +11,10 @@ end
10
11
 
11
12
 
12
13
  def new_network(url = "http://localhost:3000", player_id = "1000001")
13
- network = Libgss::Network.new(url)
14
- network.player_id = player_id
15
- network.consumer_secret = "cpqomf5gs4ob6prd5w5zd52yg9du7150"
16
- network
14
+ config = YAML.load_file(File.expand_path("../../fontana_sample/config/app_garden.yml", __FILE__))
15
+ opts = {
16
+ consumer_secret: config["consumer_secret"],
17
+ player_id: player_id
18
+ }
19
+ Libgss::Network.new(url, opts)
17
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libgss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akima
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-06-25 00:00:00.000000000 Z
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,11 +97,13 @@ dependencies:
97
97
  description: network library for Groovenauts GSS
98
98
  email:
99
99
  - t-akima@groovenauts.jp
100
- executables: []
100
+ executables:
101
+ - gss-server-time
101
102
  extensions: []
102
103
  extra_rdoc_files: []
103
104
  files:
104
105
  - .gitignore
106
+ - .gitmodules
105
107
  - .rspec
106
108
  - .travis.yml
107
109
  - Gemfile
@@ -110,10 +112,12 @@ files:
110
112
  - README.md
111
113
  - README_ja.md
112
114
  - Rakefile
115
+ - bin/gss-server-time
113
116
  - lib/libgss.rb
114
117
  - lib/libgss/action.rb
115
118
  - lib/libgss/action_request.rb
116
119
  - lib/libgss/asset_request.rb
120
+ - lib/libgss/fontana.rb
117
121
  - lib/libgss/http_client_with_signature_key.rb
118
122
  - lib/libgss/network.rb
119
123
  - lib/libgss/outputs.rb