Class: Lucid::Shopify::BulkRequest::Operation
- Inherits:
-
Object
- Object
- Lucid::Shopify::BulkRequest::Operation
- Defined in:
- lib/lucid/shopify/bulk_request.rb
Instance Method Summary collapse
-
#around(&block) ⇒ self
Set a block which is called after the file is downloaded, and around the line by line iteration in #call.
- #call(query, http: Container[:http]) {|Hash| ... } ⇒ Object
Instance Method Details
#around(&block) ⇒ self
Set a block which is called after the file is downloaded, and around the line by line iteration in #call. The block must yield control back to the caller.
37 38 39 40 41 |
# File 'lib/lucid/shopify/bulk_request.rb', line 37 def around(&block) @around = block self end |
#call(query, http: Container[:http]) {|Hash| ... } ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 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 93 |
# File 'lib/lucid/shopify/bulk_request.rb', line 54 def call(query, http: Container[:http], &block) id = client.post_graphql(credentials, " mutation {\n bulkOperationRunQuery(\n query: \"\"\"\n \#{query}\n \"\"\"\n ) {\n bulkOperation {\n id\n }\n userErrors {\n field\n message\n }\n }\n }\n QUERY\n\n url = poll(id)\n\n # TODO: Verify signature?\n\n begin\n file = Tempfile.new(mode: 0600)\n body = http.get(url).body\n until (chunk = body.readpartial).nil?\n file.write(chunk)\n end\n file.rewind\n call_around do\n file.each_line do |line|\n block.(JSON.parse(line))\n end\n end\n ensure\n file.close\n file.unlink\n end\nend\n")['data']['bulkOperationRunQuery']['bulkOperation']['id'] |