Class: Rews::Folder::BaseFolderId
- Inherits:
-
Object
- Object
- Rews::Folder::BaseFolderId
- Includes:
- Util
- Defined in:
- lib/rews/folder.rb
Direct Known Subclasses
Constant Summary collapse
- FIND_FOLDER_OPTS =
{ :restriction=>nil, :indexed_page_folder_view=>View::INDEXED_PAGE_VIEW_OPTS, :folder_shape=>Shape::FOLDER_SHAPE_OPTS}
- FIND_ITEM_OPTS =
{ :restriction=>nil, :sort_order=>nil, :indexed_page_item_view=>View::INDEXED_PAGE_VIEW_OPTS, :item_shape=>Shape::ITEM_SHAPE_OPTS}
- GET_ITEM_OPTS =
{ :item_shape=>Shape::ITEM_SHAPE_OPTS, :ignore_change_keys=>nil }
- DELETE_ITEM_OPTS =
{ :delete_type! =>nil, :ignore_change_keys=>false }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #delete_item(message_ids, opts = {}) ⇒ Object
- #find_folder(opts = {}) ⇒ Object
- #find_folder_id(opts = {}) ⇒ Object
-
#find_item(opts = {}) ⇒ Object
find message-ids in a folder.
- #find_item_id(opts = {}) ⇒ Object
-
#get_item(message_ids, opts = {}) ⇒ Object
get a bunch of messages in one api hit.
-
#initialize(client) ⇒ BaseFolderId
constructor
A new instance of BaseFolderId.
Methods included from Util
camel_keys, camelize, check_opts, single_error_check, strip_bang, with_error_check
Constructor Details
#initialize(client) ⇒ BaseFolderId
Returns a new instance of BaseFolderId.
57 58 59 |
# File 'lib/rews/folder.rb', line 57 def initialize(client) @client=client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
55 56 57 |
# File 'lib/rews/folder.rb', line 55 def client @client end |
Instance Method Details
#delete_item(message_ids, opts = {}) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/rews/folder.rb', line 184 def delete_item(, opts={}) opts = check_opts(DELETE_ITEM_OPTS, opts) = .result if .is_a?(FindResult) r = with_error_check(client, :delete_item_response, :response_messages, :delete_item_response_message) do client.request(:wsdl, "DeleteItem", :DeleteType=>opts[:delete_type]) do soap.namespaces["xmlns:t"]=SCHEMA_TYPES xml = Builder::XmlMarkup.new xml.wsdl :ItemIds do .each do |mid| xml << Gyoku.xml(mid.to_xml_hash(opts[:ignore_change_keys])) end end soap.body = xml.target! end end true end |
#find_folder(opts = {}) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rews/folder.rb', line 66 def find_folder(opts={}) opts = check_opts(FIND_FOLDER_OPTS, opts) r = with_error_check(client, :find_folder_response, :response_messages, :find_folder_response_message) do client.request(:wsdl, "FindFolder", "Traversal"=>"Shallow") do soap.namespaces["xmlns:t"]=SCHEMA_TYPES xml = Builder::XmlMarkup.new xml << Shape::FolderShape.new(opts[:folder_shape]||{}).to_xml xml << View::IndexedPageFolderView.new(opts[:indexed_page_folder_view]).to_xml if opts[:indexed_page_folder_view] xml << Restriction.new(opts[:restriction]).to_xml if opts[:restriction] xml.wsdl :ParentFolderIds do xml << Gyoku.xml(self.to_xml_hash) end soap.body = xml.target! end end FindResult.new(r.fetch_in(:root_folder)) do |view| results = view.fetch_in(:folders, :folder) results = [results] if !results.is_a?(Array) results.compact.map do |folder| Folder.new(client, folder) end end end |
#find_folder_id(opts = {}) ⇒ Object
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rews/folder.rb', line 94 def find_folder_id(opts={}) opts = check_opts(FIND_FOLDER_OPTS, opts) shape = opts[:folder_shape] ||={} shape[:base_shape]||=:IdOnly r = find_folder(opts) r.result.map!(&:folder_id) r end |
#find_item(opts = {}) ⇒ Object
find message-ids in a folder
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/rews/folder.rb', line 112 def find_item(opts={}) opts = check_opts(FIND_ITEM_OPTS, opts) r = with_error_check(client, :find_item_response, :response_messages, :find_item_response_message) do client.request(:wsdl, "FindItem", "Traversal"=>"Shallow") do soap.namespaces["xmlns:t"]=SCHEMA_TYPES xml = Builder::XmlMarkup.new xml << Shape::ItemShape.new(opts[:item_shape]||{}).to_xml xml << View::IndexedPageItemView.new(opts[:indexed_page_item_view]).to_xml if opts[:indexed_page_item_view] xml << Restriction.new(opts[:restriction]).to_xml if opts[:restriction] xml << SortOrder.new(opts[:sort_order]).to_xml if opts[:sort_order] xml.wsdl :ParentFolderIds do xml << Gyoku.xml(self.to_xml_hash) end soap.body = xml.target! end end FindResult.new(r.to_hash.fetch_in(:root_folder)) do |view| results = Item.read_items(client, view[:items]) end end |
#find_item_id(opts = {}) ⇒ Object
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/rews/folder.rb', line 139 def find_item_id(opts={}) opts = check_opts(FIND_ITEM_OPTS, opts) shape = opts[:item_shape] ||= {} shape[:base_shape]||=:IdOnly r = find_item(opts) r.result.map!(&:item_id) r end |
#get_item(message_ids, opts = {}) ⇒ Object
get a bunch of messages in one api hit
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/rews/folder.rb', line 156 def get_item(, opts={}) opts = check_opts(GET_ITEM_OPTS, opts) = .result if .is_a?(FindResult) r = with_error_check(client, :get_item_response,:response_messages,:get_item_response_message) do client.request(:wsdl, "GetItem") do soap.namespaces["xmlns:t"]=SCHEMA_TYPES xml = Builder::XmlMarkup.new xml << Shape::ItemShape.new(opts[:item_shape]||{}).to_xml xml.wsdl :ItemIds do .each do |mid| xml << Gyoku.xml(mid.to_xml_hash(opts[:ignore_change_keys])) end end soap.body = xml.target! end end Item.(client, r) end |