Class: BizhubTool::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bizhub-tool/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, username, password) ⇒ Client



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bizhub-tool/client.rb', line 9

def initialize(url, username, password)
  self.url = URI.parse(url)
  self.username = username
  self.password = password
  if self.confirm_connect
    if self.
      true
    else
      raise ArgumentError, "user/name password invalid"
    end
  else
    raise ArgumentError, "unable to connect"
  end
end

Instance Attribute Details

#auth_key ⇒ Object

Returns the value of attribute auth_key.



7
8
9
# File 'lib/bizhub-tool/client.rb', line 7

def auth_key
  @auth_key
end

#lock_key ⇒ Object

Returns the value of attribute lock_key.



7
8
9
# File 'lib/bizhub-tool/client.rb', line 7

def lock_key
  @lock_key
end

#password ⇒ Object

Returns the value of attribute password.



7
8
9
# File 'lib/bizhub-tool/client.rb', line 7

def password
  @password
end

#url ⇒ Object

Returns the value of attribute url.



7
8
9
# File 'lib/bizhub-tool/client.rb', line 7

def url
  @url
end

#username ⇒ Object

Returns the value of attribute username.



7
8
9
# File 'lib/bizhub-tool/client.rb', line 7

def username
  @username
end

Instance Method Details

#confirm_connect ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bizhub-tool/client.rb', line 24

def confirm_connect
  # url = URI.parse('http://geoffrey.synapsedev.com:50001/')
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqConfirmConnect xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><UserType>\#{self.username}</UserType><Password>\#{self.password}</Password></OperatorInfo></AppReqConfirmConnect>\n  TEXT\n  request.body = self.class.generate_request(body)\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response.body\n  response_hash = Nori.parse(response.body)\n  request_hash = Nori.parse(request.body)\n  puts response_hash\n  log_response(response_hash, request.body, \"app_res_confirm_connect\", __method__)\nend\n"

#delete_abbr(abbr_no) ⇒ Object



114
115
116
117
118
119
120
121
122
123
# File 'lib/bizhub-tool/client.rb', line 114

def delete_abbr(abbr_no)
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqDeleteAbbr xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><AuthKey>\#{self.auth_key}</AuthKey></OperatorInfo><LockKey>\#{self.lock_key}</LockKey><AllItem>false</AllItem><AddressKind>Public</AddressKind><AbbrNo>\#{abbr_no}</AbbrNo></AppReqDeleteAbbr>\n  TEXT\n  request.body = self.class.generate_request(body)\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response_hash = Nori.parse(response.body)\n  log_response(response_hash, request.body, \"app_res_delete_abbr\", __method__)\nend\n"

#enter_device_lock ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bizhub-tool/client.rb', line 58

def enter_device_lock
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqEnterDeviceLock xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><AuthKey>\#{self.auth_key}</AuthKey></OperatorInfo><LockType>DownloadLock</LockType><PackageEntryFlg>Package</PackageEntryFlg><TimeOut>60</TimeOut></AppReqEnterDeviceLock>\n  TEXT\n  request.body = self.class.generate_request(body)\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response.body\n  response_hash = Nori.parse(response.body)\n  if log_response(response_hash, request.body, \"app_res_enter_device_lock\", __method__)\n    self.lock_key = response_hash[:envelope][:body][:app_res_enter_device_lock][:lock_key]\n    true\n  else\n    false\n  end\nend\n"

#exit_device_lock ⇒ Object



75
76
77
78
79
80
81
82
83
84
# File 'lib/bizhub-tool/client.rb', line 75

def exit_device_lock
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqExitDeviceLock xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><AuthKey>\#{self.auth_key}</AuthKey></OperatorInfo><LockKey>\#{self.lock_key}</LockKey></AppReqExitDeviceLock>\n  TEXT\n  request.body = self.class.generate_request(body)\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response_hash = Nori.parse(response.body)\n  log_response(response_hash, request.body, \"app_res_exit_device_lock\", __method__)\nend\n"

#get_abbr(start, length) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/bizhub-tool/client.rb', line 99

def get_abbr(start, length)
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqGetAbbr xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><AuthKey>\#{self.auth_key}</AuthKey></OperatorInfo><AbbrListCondition><SearchKey>None</SearchKey><WellUse>false</WellUse><ObtainCondition><Type>OffsetList</Type><OffsetRange><Start>\#{start}</Start><Length>\#{length}</Length></OffsetRange></ObtainCondition><BackUp>true</BackUp><BackUpPassword>MYSKIMGS</BackUpPassword></AbbrListCondition></AppReqGetAbbr>\n  TEXT\n  request.body = self.class.generate_request(body)\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response_hash = Nori.parse(response.body)\n  if log_response(response_hash, request.body, \"app_res_get_abbr\", __method__)\n    response_hash\n  else\n    false\n  end\nend\n"

#get_max_abbr ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/bizhub-tool/client.rb', line 125

def get_max_abbr
  array_size = 100
  start_value = 1
  results = true
  
  while results == true
    puts start_value
    response = self.get_abbr(start_value, array_size)
    if response[:envelope][:body][:app_res_get_abbr][:abbr_list][:array_size].to_i == array_size
      start_value += array_size
    else
      results = false
      max_abbr = response[:envelope][:body][:app_res_get_abbr][:abbr_list][:abbr].last[:abbr_no]
    end
  end
  max_abbr
end

#login ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bizhub-tool/client.rb', line 39

def 
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqLogin xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><UserType>\#{self.username}</UserType><Password>\#{self.password}</Password></OperatorInfo><TimeOut>60</TimeOut></AppReqLogin>\n  TEXT\n  request.body = self.class.generate_request(body)\n  puts request.body\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response.body\n  response_hash = Nori.parse(response.body)\n  if log_response(response_hash, request.body, \"app_res_login\", __method__)\n    self.auth_key = response_hash[:envelope][:body][:app_res_login][:auth_key]\n    true\n  else\n    false\n  end\nend\n"

#set_abbr(first_name, last_name, email, abbr_no) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bizhub-tool/client.rb', line 86

def set_abbr(first_name, last_name, email, abbr_no)
  search_key = self.class.find_search_key(last_name)
  full_name = [first_name, last_name].join(" ")
  request = Net::HTTP::Post.new(self.url.path)
  body ="  <AppReqSetAbbr xmlns=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><OperatorInfo><AuthKey>\#{self.auth_key}</AuthKey></OperatorInfo><CreateCondition><Auto>false</Auto><OverWrite>true</OverWrite></CreateCondition><LockKey>\#{self.lock_key}</LockKey><Abbr xmlns:m=\"http://www.konicaminolta.com/service/OpenAPI-4-2\"><AbbrNo>\#{abbr_no}</AbbrNo><Name>\#{full_name}</Name><SearchKey>\#{search_key}</SearchKey><WellUse>false</WellUse><SendConfiguration><SendGroup>Scan</SendGroup><TargetAddressType>Single</TargetAddressType><AddressInfo><SendMode>Email</SendMode><EmailMode><To>\#{email}</To></EmailMode><ImageType>Icon</ImageType><IconID>1</IconID><PhotoEditFlag>NotRegistered</PhotoEditFlag></AddressInfo></SendConfiguration><FaxConfiguration /><EditFlag>Appended</EditFlag><ReferLicence><UseReferLicence>Level</UseReferLicence><ReferGroupNo>1</ReferGroupNo><ReferPossibleLevel>0</ReferPossibleLevel></ReferLicence><AddressKind>Public</AddressKind></Abbr></AppReqSetAbbr>\n  TEXT\n  request.body = self.class.generate_request(body)\n  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}\n  response_hash = Nori.parse(response.body)\n  log_response(response_hash, request.body, \"app_res_set_abbr\", __method__)\nend\n"