Class: BizhubTool::Client
- Inherits:
-
Object
- Object
- BizhubTool::Client
- Defined in:
- lib/bizhub-tool/client.rb
Instance Attribute Summary collapse
-
#auth_key ⇒ Object
Returns the value of attribute auth_key.
-
#lock_key ⇒ Object
Returns the value of attribute lock_key.
-
#password ⇒ Object
Returns the value of attribute password.
-
#url ⇒ Object
Returns the value of attribute url.
-
#username ⇒ Object
Returns the value of attribute username.
Instance Method Summary collapse
- #confirm_connect ⇒ Object
- #delete_abbr(abbr_no) ⇒ Object
- #enter_device_lock ⇒ Object
- #exit_device_lock ⇒ Object
- #get_abbr(start, length) ⇒ Object
- #get_max_abbr ⇒ Object
-
#initialize(url, username, password) ⇒ Client
constructor
A new instance of Client.
- #login ⇒ Object
- #set_abbr(first_name, last_name, email, abbr_no) ⇒ Object
Constructor Details
#initialize(url, username, password) ⇒ Client
Returns a new instance of 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.login 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 =<<-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
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 =<<-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_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 =<<-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_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 =<<-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
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 =<<-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_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 login 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
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 =<<-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 |