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

Returns a new instance of Client.



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

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_keyObject

Returns the value of attribute auth_key.



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

def auth_key
  @auth_key
end

#lock_keyObject

Returns the value of attribute lock_key.



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

def lock_key
  @lock_key
end

#passwordObject

Returns the value of attribute password.



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

def password
  @password
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

#usernameObject

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

#confirm_connectObject



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

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

#delete_abbr(abbr_no) ⇒ Object



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

def delete_abbr(abbr_no)
  request = Net::HTTP::Post.new(self.url.path)
  body =<<-TEXT
  <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>
  TEXT
  request.body = self.class.generate_request(body)
  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
  response_hash = Nori.parse(response.body)
  log_response(response_hash, request.body, "app_res_delete_abbr", __method__)
end

#enter_device_lockObject



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

def enter_device_lock
  request = Net::HTTP::Post.new(self.url.path)
  body =<<-TEXT
  <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>
  TEXT
  request.body = self.class.generate_request(body)
  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
  response.body
  response_hash = Nori.parse(response.body)
  if log_response(response_hash, request.body, "app_res_enter_device_lock", __method__)
    self.lock_key = response_hash[:envelope][:body][:app_res_enter_device_lock][:lock_key]
    true
  else
    false
  end
end

#exit_device_lockObject



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

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

#get_abbr(start, length) ⇒ Object



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

def get_abbr(start, length)
  request = Net::HTTP::Post.new(self.url.path)
  body =<<-TEXT
  <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>
  TEXT
  request.body = self.class.generate_request(body)
  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
  response_hash = Nori.parse(response.body)
  if log_response(response_hash, request.body, "app_res_get_abbr", __method__)
    response_hash
  else
    false
  end
end

#get_max_abbrObject



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

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

#loginObject



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

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

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



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

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 =<<-TEXT
  <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>
  TEXT
  request.body = self.class.generate_request(body)
  response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
  response_hash = Nori.parse(response.body)
  log_response(response_hash, request.body, "app_res_set_abbr", __method__)
end