12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/fletcher/cli/utility.rb', line 12
def fetch(url)
product = Fletcher.fetch url
output_hash = Hash.new
output_hash["name"] = product.name
output_hash["description"] = product.description if product.description
output_hash["price"] = product.price.format if product.price
if product.image
output_hash["image"] = Hash.new
output_hash["image"]["src"] = product.image.src
end
output_hash["url"] = product.url
if options[:only]
case options[:only]
when "image"
value = output_hash["image"]["src"]
else
value = output_hash[options[:only]]
end
value ? say(value.to_s) : say("Unknown attribute: #{options[:only]}")
else
say output_hash.to_yaml
end
if options[:debug]
say "user_agent: #{Fletcher::USER_AGENT}"
say "response:\n\n"
say product.doc.to_s
end
end
|