libgss 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8797c13b87ab107f028edd43426b237b403d54a7
4
- data.tar.gz: 2218823fcf1255e345c0d4cc580c277156dd0e52
3
+ metadata.gz: 0f34218d9370b8d31892b2dc9bc43883c18d3c0b
4
+ data.tar.gz: d77691024b3ea4a7bb346f6aac4503896383e1c6
5
5
  SHA512:
6
- metadata.gz: a58f6d8956dc0b13dd01bc606961a2edfc82f8d8e5ed416911f014e2fa2101e453f5b43c54fd46abaaf8b3290ec1ed1ffca46ee7e22422cd1dff7a7cb247cf1b
7
- data.tar.gz: 7dea0c14e99e1a11785969675ec43ac3d2c411188ac7b82e01215032ab5e99cd2cd81507005a509b5cdac9192f33730270de5dde3a1297b08a1eb7632adf6c74
6
+ metadata.gz: ea8da56f9d588bfd1b9d1970749ea87b7ed09a565caf8675ebf4c7ad7770223079f0331489a2daa97d20a7c82e425ea666df9ce1b4a00623b11e36249a18b255
7
+ data.tar.gz: 96bc30423526821e4074b20d1cfcc26d7a5f4f850955cfb77f902e43a1e7f2420b1a1e7d7c1227abf42a1f8da79154eb5deb2f6f253f38c5a0a7b8edf1758b13
data/Gemfile.lock CHANGED
@@ -1,11 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- libgss (0.6.1)
4
+ libgss (0.7.0)
5
5
  httpclient
6
6
  json
7
7
  oauth
8
- tengine_support
9
8
 
10
9
  GEM
11
10
  remote: https://rubygems.org/
@@ -39,3 +38,4 @@ DEPENDENCIES
39
38
  libgss!
40
39
  rake
41
40
  rspec
41
+ tengine_support
@@ -0,0 +1,46 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'libgss'
3
+
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module Libgss
8
+
9
+ class AsyncActionRequest < ActionRequest
10
+
11
+ attr_reader :ids
12
+ attr_accessor :action_id
13
+
14
+ # アクション群を実行するために実際にHTTPリクエストを送信します。
15
+ def send_request(&callback)
16
+ res = @httpclient.post(action_url, {"inputs" => @actions.map(&:to_hash)}.to_json, req_headers)
17
+ case res.code.to_i
18
+ when 200..299 then # OK
19
+ else
20
+ raise Error, "failed to send action request: [#{res.code}] #{res.body}"
21
+ end
22
+ r = JSON.parse(res.body)
23
+ # puts res.body
24
+ @outputs = Outputs.new(r["outputs"])
25
+ callback.call(@outputs) if callback
26
+
27
+ @ids = @outputs.map do |output|
28
+ output['id']
29
+ end
30
+
31
+ @outputs
32
+ end
33
+
34
+ def async_status()
35
+ raise Error, "failed to get response. please exec send_request before call." unless @ids
36
+
37
+ res = @httpclient.get(action_url, {input_ids: @ids.join(',')}, req_headers)
38
+ case res.code.to_i
39
+ when 200..299 then # OK
40
+ else
41
+ raise Error, "failed to send action request: [#{res.code}] #{res.body}"
42
+ end
43
+ r = JSON.parse(res.body)
44
+ end
45
+ end
46
+ end
@@ -5,6 +5,11 @@ require 'oauth'
5
5
 
6
6
  require 'digest/hmac'
7
7
 
8
+ require 'uri'
9
+
10
+ require 'securerandom'
11
+
12
+
8
13
  module Libgss
9
14
  class HttpClientWithSignatureKey
10
15
 
@@ -17,6 +22,8 @@ module Libgss
17
22
  headers = {
18
23
  "oauth_consumer_key" => network.consumer_key || "",
19
24
  "oauth_token" => network.auth_token,
25
+ "oauth_nonce" => oauth_nonce,
26
+ "oauth_timestamp" => oauth_timestamp,
20
27
  }
21
28
  oauth_params = {
22
29
  "body" => body,
@@ -42,6 +49,66 @@ module Libgss
42
49
  res = @impl.post(uri, body, headers.update(original_headers))
43
50
  end
44
51
 
52
+ def get(uri, query={}, original_headers = {}, &block)
53
+ headers = {
54
+ "oauth_consumer_key" => network.consumer_key || "",
55
+ "oauth_token" => network.auth_token,
56
+ "oauth_nonce" => oauth_nonce,
57
+ "oauth_timestamp" => oauth_timestamp,
58
+ }
59
+ oauth_params = {
60
+ "oauth_signature_method" => "HMAC-SHA1"
61
+ }.update(headers)
62
+
63
+ encoded_query = ''
64
+ query.each do |key, val|
65
+ key = key.to_s
66
+ if val.is_a?(::Array)
67
+ k = CGI.escape("#{key}[]")
68
+ val.each do |v|
69
+ encoded_query << "&#{k}=#{URI.escape(v.to_s)}"
70
+ end
71
+ elsif val.is_a?(::Hash)
72
+ val.each do |k, v|
73
+ k = URI.escape("#{key}[#{k}]")
74
+ encoded_query << "&#{k}=#{URI.escape(v.to_s)}"
75
+ end
76
+ else
77
+ encoded_query << "&#{URI.escape(key)}=#{URI.escape(val.to_s)}"
78
+ end
79
+ end
80
+ if uri =~ /\?/
81
+ uri += encoded_query
82
+ else
83
+ uri += encoded_query.gsub(/^&/, '?')
84
+ end
85
+ req_hash = {
86
+ "method" => "POST",
87
+ "uri" => uri,
88
+ "parameters" => oauth_params
89
+ }
90
+
91
+ options = {
92
+ :consumer_secret => network.consumer_secret,
93
+ :token_secret => network.signature_key
94
+ }
95
+
96
+ signature_class = Libgss.use_oauth_gem ? ::OAuth::Signature : Signature
97
+ $stdout.puts("signature_class: #{signature_class.name}") if ENV["VERBOSE"]
98
+
99
+ headers["oauth_signature"] = signature_class.sign(req_hash, options)
100
+
101
+ res = @impl.get(uri, nil, headers.update(original_headers))
102
+ end
103
+
104
+ def oauth_nonce
105
+ SecureRandom.uuid.to_s
106
+ end
107
+
108
+ def oauth_timestamp
109
+ Time.now.utc.to_i
110
+ end
111
+
45
112
  class Signature
46
113
  class << self
47
114
  def sign(req_hash, options)
@@ -117,6 +117,10 @@ module Libgss
117
117
  ActionRequest.new(httpclient_for_action, action_url, req_headers)
118
118
  end
119
119
 
120
+ def new_async_action_request
121
+ AsyncActionRequest.new(httpclient_for_action, aync_action_url, req_headers)
122
+ end
123
+
120
124
  def new_public_asset_request(asset_path)
121
125
  AssetRequest.new(@httpclient, public_asset_url(asset_path), req_headers)
122
126
  end
@@ -179,6 +183,10 @@ module Libgss
179
183
  @action_url ||= base_url + "/api/#{API_VERSION}/actions.json?auth_token=#{auth_token}"
180
184
  end
181
185
 
186
+ def aync_action_url
187
+ @async_action_url ||= base_url + "/api/#{API_VERSION}/async_actions.json?auth_token=#{auth_token}"
188
+ end
189
+
182
190
  def public_asset_url(asset_path)
183
191
  "#{@public_asset_url_prefix}#{asset_path}#{@public_asset_url_suffix}"
184
192
  end
@@ -1,3 +1,3 @@
1
1
  module Libgss
2
- VERSION = "0.6.2"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/libgss.rb CHANGED
@@ -5,6 +5,7 @@ module Libgss
5
5
  autoload :Network , "libgss/network"
6
6
  autoload :Action , "libgss/action"
7
7
  autoload :ActionRequest, "libgss/action_request"
8
+ autoload :AsyncActionRequest, "libgss/async_action_request"
8
9
  autoload :Outputs , "libgss/outputs"
9
10
  autoload :HttpClientWithSignatureKey, "libgss/http_client_with_signature_key"
10
11
 
@@ -0,0 +1,32 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Libgss::AsyncActionRequest do
5
+ before do
6
+ request_fixture_load("01_basic")
7
+ end
8
+
9
+ let(:network) do
10
+ network = new_network
11
+ network.login.should == true
12
+ network
13
+ end
14
+
15
+ let(:request) do
16
+ network.new_async_action_request
17
+ end
18
+
19
+ describe "#get" do
20
+ context "Player" do
21
+ it do
22
+ request.get_by_player
23
+ request.send_request do |outputs|
24
+ outputs.length.should == 1
25
+ outputs[0]['status'].should eq('executing')
26
+ end
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ 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.6.2
4
+ version: 0.7.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-09-12 00:00:00.000000000 Z
11
+ date: 2013-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,6 +131,7 @@ files:
131
131
  - lib/libgss/action.rb
132
132
  - lib/libgss/action_request.rb
133
133
  - lib/libgss/asset_request.rb
134
+ - lib/libgss/async_action_request.rb
134
135
  - lib/libgss/fontana.rb
135
136
  - lib/libgss/http_client_with_signature_key.rb
136
137
  - lib/libgss/network.rb
@@ -148,6 +149,7 @@ files:
148
149
  - spec/libgss/actions/ruby_stored_script_spec.rb
149
150
  - spec/libgss/actions/schedule_spec.rb
150
151
  - spec/libgss/asset_request_spec.rb
152
+ - spec/libgss/async_action_request_spec.rb
151
153
  - spec/libgss/network_spec.rb
152
154
  - spec/protected_assets/Icon.png
153
155
  - spec/public_assets/Default.png
@@ -188,6 +190,7 @@ test_files:
188
190
  - spec/libgss/actions/ruby_stored_script_spec.rb
189
191
  - spec/libgss/actions/schedule_spec.rb
190
192
  - spec/libgss/asset_request_spec.rb
193
+ - spec/libgss/async_action_request_spec.rb
191
194
  - spec/libgss/network_spec.rb
192
195
  - spec/protected_assets/Icon.png
193
196
  - spec/public_assets/Default.png