Class: Mushikago::Mitsubachi::Client

Inherits:
Http::Client show all
Defined in:
lib/mushikago/mitsubachi/client.rb

Overview

mitsubachiサービスを利用する

Examples:

require 'mushikago'
client = Mushikago::Mitsubachi::Client.new(:api_key => '<api_key>', :secret_key => '<secret_key>')

client.project_create('project01')
client.script_deploy('project01', 'sample.rb', 'sample.rb')
client.http_fetch('project01', 'http://www.mushikago.org/', 'sample.rb')

APIキーをファイルから読み込む場合

Mushikago.config.load(YAML.load(File.read('config.yml')))
client = Mushikago::Mitsubachi::Client.new

Instance Attribute Summary

Attributes inherited from Http::Client

api_key, signer

Instance Method Summary (collapse)

Methods inherited from Http::Client

#initialize, #send_request

Constructor Details

This class inherits a constructor from Mushikago::Http::Client

Instance Method Details

- (Mushikago::Http::Response) http_fetch(project_name, url, script_name, options = {})

http/fetchを発行します

Examples:

client.http_fetch('project01', 'http://www.tombo.ne.jp/', 'sample.rb', :follow_redirect => true)

Parameters:

  • project_name (String)

    プロジェクト名

  • url (String)

    クロール対象のURL

  • script_name (String)

    スクレイピングスクリプトのパス

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :method (String)
  • :entity_parameter (String)
  • :follow_redirect (Boolean)
  • :parameters (String)
  • :header_overwrite (String)

Returns:



143
144
145
146
# File 'lib/mushikago/mitsubachi/client.rb', line 143

def http_fetch project_name, url, script_name, options={}
  request = HttpFetchRequest.new(project_name, url, script_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) http_push(project_name, url, script_name, file_name, file_input_key, options = {})

http/pushを発行します

Examples:

client.http_push('project01', 'http://www.tombo.ne.jp/', 'sample.rb')

Parameters:

  • project_name (String)

    プロジェクト名

  • url (String)

    クロール対象のURL

  • script_name (String)

    スクレイピングスクリプトのパス

  • file_name (String)
  • file_input_key (String)
  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :entity_parameter (String)
  • :parameters (String)
  • :header_overwrite (String)
  • :mime_type (String)

Returns:



163
164
165
166
# File 'lib/mushikago/mitsubachi/client.rb', line 163

def http_push project_name, url, script_name, file_name, file_input_key, options={}
  request = HttpPushRequest.new(project_name, url, script_name, file_name, file_input_key, options)
  send_request(request)
end

- (Mushikago::Http::Response) project_create(project_name, options = {})

project/createを発行します

Examples:

client.project_create('project01', :stdout => true)

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :dedicated (Boolean)
  • :max_lead_time (Integer)
  • :stdout (Boolean)
  • :stderr (Boolean)
  • :system_log (Boolean)
  • :log_prefix (String)

Returns:



31
32
33
34
# File 'lib/mushikago/mitsubachi/client.rb', line 31

def project_create project_name, options={}
  request = ProjectCreateRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) project_delete(project_name, options = {})

project/deleteを発行します

Examples:

client.project_delete('project01')

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :forcedelete (Boolean)

Returns:



95
96
97
98
# File 'lib/mushikago/mitsubachi/client.rb', line 95

def project_delete project_name, options={}
  request = ProjectDeleteRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) project_discontinue(project_name, options = {})

project/discontinueを発行します

Examples:

client.project_discontinue('project01')

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



124
125
126
127
# File 'lib/mushikago/mitsubachi/client.rb', line 124

def project_discontinue project_name, options={}
  request = ProjectDiscontinueRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) project_info(project_name, options = {})

project/infoを発行します

Examples:

result = client.project_info('project01')
puts result['dedicated']
puts result['max_lead_time']
puts result['stdout']
puts result['stderr']
puts result['system_log']
puts result['log_prefix']
puts result['count']
puts result['usage']
puts result['storage_prefix']

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



69
70
71
72
# File 'lib/mushikago/mitsubachi/client.rb', line 69

def project_info project_name, options={}
  request = ProjectInfoRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) project_list(options = {})

project/listを発行します

Examples:

result = client.project_list
result['projects'].each do |project|
  puts project['name']
end

Parameters:

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)

Returns:



48
49
50
51
# File 'lib/mushikago/mitsubachi/client.rb', line 48

def project_list options={}
  request = ProjectListRequest.new(options)
  send_request(request)
end

- (Mushikago::Http::Response) project_queues(project_name, options = {})

project/queuesを発行します

Examples:

result = client.project_queues('project01')
puts result['count']

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



82
83
84
85
# File 'lib/mushikago/mitsubachi/client.rb', line 82

def project_queues project_name, options={}
  request = ProjectQueuesRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) project_update(project_name, options = {})

project/updateを発行します

Examples:

client.project_update('project01', :stdout => false)

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :max_lead_time (Integer)
  • :stdout (Boolean)
  • :stderr (Boolean)
  • :system_log (Boolean)
  • :log_prefix (String)

Returns:



112
113
114
115
# File 'lib/mushikago/mitsubachi/client.rb', line 112

def project_update project_name, options={}
  request = ProjectUpdateRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) resource_delete(project_name, file_name, options = {})

resource/deleteを発行します

Examples:

client.resource_delete('project01', 'sample.rb')

Parameters:

  • project_name (String)

    プロジェクト名

  • file_name (String)

    保存先のファイル名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



301
302
303
304
# File 'lib/mushikago/mitsubachi/client.rb', line 301

def resource_delete project_name, file_name, options={}
  request = ResourceDeleteRequest.new(project_name, file_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) resource_get(project_name, file_name, options = {})

resource/getを発行します

Examples:

result = client.resource_get('project01', 'sample.rb')
puts result['url']

Parameters:

  • project_name (String)

    プロジェクト名

  • file_name (String)

    保存先のファイル名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



288
289
290
291
# File 'lib/mushikago/mitsubachi/client.rb', line 288

def resource_get project_name, file_name, options={}
  request = ResourceGetRequest.new(project_name, file_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) resource_list(project_name, options = {})

resource/listを発行します

Examples:

limit = 10
offset = 0
has_more_files = 1
until has_more_files == 0
  result = client.resource_list('project01', :limit => limit, :offset => offset)
  result['files'].each do |file|
    puts script['name']
    puts script['size']
    puts script['timestamp']
  end
  offset += limit
  has_more_files = result['has_more_files']
end

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)

Returns:



274
275
276
277
# File 'lib/mushikago/mitsubachi/client.rb', line 274

def resource_list project_name, options={}
  request = ResourceListRequest.new(project_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) resource_store(project_name, file_or_file_name, options = {})

resource/storeを発行します

Examples:

client.resource_store('project01', 'sample.csv', :public => true)

Parameters:

  • project_name (String)

    プロジェクト名

  • file_or_file_name (String or File)

    デプロイするファイルオブジェクトもしくはファイルパス

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :file_name (String)

    デプロイ先のファイル名

  • :content_type (String)
  • :public (public)

Returns:



247
248
249
250
# File 'lib/mushikago/mitsubachi/client.rb', line 247

def resource_store project_name, file_or_file_name, options={}
  request = ResourceStoreRequest.new(project_name, file_or_file_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) script_delete(project_name, script_name, options = {})

script/deleteを発行します

Examples:

client.script_delete('project01', 'sample.rb')

Parameters:

  • project_name (String)

    プロジェクト名

  • script_name (String)

    デプロイ先のファイル名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



231
232
233
234
# File 'lib/mushikago/mitsubachi/client.rb', line 231

def script_delete project_name, script_name, options={}
  request = ScriptDeleteRequest.new(project_name, script_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) script_deploy(project_name, file_or_file_name, options = {})

script/deployを発行します

Examples:

client.script_deploy('project01', 'sample.rb', :script_name => 'hoge.rb')

Parameters:

  • project_name (String)

    プロジェクト名

  • file_or_file_name (String or File)

    デプロイするファイルオブジェクトもしくはファイルパス

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • script_name (String)

    デプロイ先のファイル名

Returns:



177
178
179
180
# File 'lib/mushikago/mitsubachi/client.rb', line 177

def script_deploy project_name, file_or_file_name, options={}
  request = ScriptDeployRequest.new(project_name, file_or_file_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) script_get(project_name, script_name, options = {})

script/getを発行します

Examples:

result = client.script_get('project01', 'sample.rb')
puts result['url']

Parameters:

  • project_name (String)

    プロジェクト名

  • script_name (String)

    デプロイ先のファイル名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Returns:



218
219
220
221
# File 'lib/mushikago/mitsubachi/client.rb', line 218

def script_get project_name, script_name, options={}
  request = ScriptGetRequest.new(project_name, script_name, options)
  send_request(request)
end

- (Mushikago::Http::Response) script_list(project_name, options = {})

script/listを発行します

Examples:

limit = 10
offset = 0
has_more_files = 1
until has_more_files == 0
  result = client.script_list('project01', :limit => limit, :offset => offset)
  result['scripts'].each do |script|
    puts script['name']
    puts script['size']
    puts script['timestamp']
  end
  offset += limit
  has_more_files = result['has_more_files']
end

Parameters:

  • project_name (String)

    プロジェクト名

  • options (Hash) (defaults to: {})

    リクエストのオプション

Options Hash (options):

  • :limit (Integer)
  • :offset (Integer)
  • :filter (String)

Returns:



204
205
206
207
# File 'lib/mushikago/mitsubachi/client.rb', line 204

def script_list project_name, options={}
  request = ScriptListRequest.new(project_name, options)
  send_request(request)
end