Class: Pantograph::Actions::DownloadAction
Constant Summary
Pantograph::Action::AVAILABLE_CATEGORIES, Pantograph::Action::RETURN_TYPES
Class Method Summary
collapse
action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text
Class Method Details
.authors ⇒ Object
68
69
70
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 68
def self.authors
['KrauseFx']
end
|
.available_options ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 39
def self.available_options
[
PantographCore::ConfigItem.new(
key: :url,
env_name: 'DOWNLOAD_URL',
description: 'The URL that should be downloaded',
verify_block: proc do |value|
UI.important('The URL does not start with http or https') unless value.start_with?('http')
end
)
]
end
|
.category ⇒ Object
64
65
66
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 64
def self.category
:misc
end
|
.description ⇒ Object
28
29
30
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 28
def self.description
'Download a file from a remote server (e.g. JSON file)'
end
|
.details ⇒ Object
32
33
34
35
36
37
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 32
def self.details
[
'Specify the URL to download and get the content as a return value.',
'Automatically parses JSON into a Ruby data structure.'
].join("\n")
end
|
.example_code ⇒ Object
58
59
60
61
62
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 58
def self.example_code
[
'data = download(url: "https://host.com/api.json")'
]
end
|
.is_supported?(platform) ⇒ Boolean
72
73
74
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 72
def self.is_supported?(platform)
true
end
|
.output ⇒ Object
52
53
54
55
56
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 52
def self.output
[
['DOWNLOAD_CONTENT', 'The content of the file we just downloaded']
]
end
|
.run(params) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'pantograph/lib/pantograph/actions/download.rb', line 8
def self.run(params)
require 'net/http'
begin
result = Net::HTTP.get(URI(params[:url]))
begin
result = JSON.parse(result) rescue
end
Actions.lane_context[SharedValues::DOWNLOAD_CONTENT] = result
rescue => ex
UI.user_error!("Error fetching remote file: #{ex}")
end
end
|