Class: Argos::SoapCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/argos/soap_command.rb

Overview

argos-soap command

On success, data is pumped to STDOUT, on faults/errors to STDERR

Examples: $ argos-soap –operation getXml $ argos-soap -o getXml –startDate=“2014-03-10T00:00:00Z” –endDate=“2014-03-10T23:59:59.999Z” –log-level=0 $ argos-soap -o getXml –date=“`date –date=yesterday -I` –username=**** –password=***** > /my/argos/xml/archive/`date -I –date=yesterday`.xml

Constant Summary

CMD =
"argos-soap"
PARAM =
{ format: :json, wsdl: Argos::Soap::WSDL, level: 1 }

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (SoapCommand) initialize(argv = ARGV, param = PARAM)

Returns a new instance of SoapCommand



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
138
139
140
141
# File 'lib/argos/soap_command.rb', line 34

def initialize(argv=ARGV, param = PARAM)
  @param = param

  option_parser = OptionParser.new(argv) do |opts|
  
    opts.version = Argos::VERSION
  
    opts.banner = "#{CMD} operation [options]\n"

    opts.on("--debug", "Debug (alias for --log-level=0)") do
      @param[:level] = Logger::DEBUG
    end
    
    # --date shorthand for 1 day period
    opts.on("--date=isodate", "Set period to one day") do |isodate|
      startDate = Time.parse(isodate+"T00:00:00Z").iso8601
      endDate = Time.parse(isodate+"T23:59:59.999Z").iso8601
      @param[:period] = { startDate: startDate,  endDate: endDate }
    end

    opts.on("--format=format", "-f=format", "{ json | xml | text | raw }") do |format|
      @param[:format] = format.to_sym
    end
    
    opts.on("--operation=operation", "-o=operation", "{ #{operations.join(" | ")} }") do |operation|
      @param[:operation] = operation.to_sym
      # Change format (from JSON) for XML and text-operations
      if [:getKml, :getObsXml, :getStreamXml, :getXml, :getXsd].include? param[:operation]
        @param[:format] = :xml
      elsif [:getCsv].include? param[:operation]
        @param[:format] = :text
      end          
    end
    
    opts.on("--log-level=level", "Log level") do |level|
      @param[:level] = level.to_i
    end
    
    opts.on("--nbDaysFromNow=days", "Set number of days") do |nbDaysFromNow|
      @param[:nbDaysFromNow] = nbDaysFromNow
    end
    
    opts.on("--startDate=dateTime", "Set period start") do |startDate|
      @param[:period] = { startDate: startDate}
    end
    
    opts.on("--endDate=dateTime", "Set period end") do |endDate|
      @param[:period] = (@param[:period]||{}).merge({ endDate: endDate })
    end
    
    opts.on("--operations", "List operations") do
      @param[:operation] = :operations
    end
            
    opts.on("--platforms", "List platforms") do
      @param[:operation] = :platforms
    end
    
    opts.on("--programs", "List programs") do
      @param[:operation] = :programs
    end
    
    opts.on("--programNumber=program1,program2", "Set programNumber(s)") do |programNumber|
      @param[:programNumber] = programNumber
    end
    
    opts.on("--platformId=platform1,platform2", "Set platformId(s)") do |platformId|
      @param[:platformId] = platformId
    end

    opts.on("--services", "Services (from WSDL)") do
      @param[:operation] = :services
    end

    opts.on("--username=username", "Set username") do |username|
      if not username.nil?
        @param[:username] = username
      end
    end
    
    opts.on("--password=password", "Set passord") do |password|
      if not password.nil?
        @param[:password] = password
      end
    end
    
    opts.on("--download=/path/to/archive", "Download") do |archive|
      @param[:archive] = archive
    end

  end
  option_parser.parse!
  
  @log = Logger.new(STDERR)
  @log.level = param[:level].to_i
  
  if not @param[:archive].nil?
    Argos::Download.download(param[:username], param[:password], param[:archive], log)
    exit(true)
  end

  if operation.nil?
    STDOUT.write option_parser.help
    exit(false)
  end
  

end

Instance Attribute Details

- (Object) log

Returns the value of attribute log



32
33
34
# File 'lib/argos/soap_command.rb', line 32

def log
  @log
end

- (Object) param

Returns the value of attribute param



32
33
34
# File 'lib/argos/soap_command.rb', line 32

def param
  @param
end

- (Object) result

Returns the value of attribute result



32
33
34
# File 'lib/argos/soap_command.rb', line 32

def result
  @result
end

- (Object) soap

Returns the value of attribute soap



32
33
34
# File 'lib/argos/soap_command.rb', line 32

def soap
  @soap
end

Class Method Details

+ (Object) run(argv = ARGV)



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/argos/soap_command.rb', line 20

def self.run(argv=ARGV)
  begin
    cmd = new(argv)
    cmd.run
    exit(true)
  rescue => e
    STDERR.write e
    STDERR.write e.backtrace.join("\n")
    exit(false)
  end
end

Instance Method Details

- (Boolean) debug?

Returns:

  • (Boolean)


143
144
145
# File 'lib/argos/soap_command.rb', line 143

def debug?
  @param[:level] == Logger::DEBUG
end

- (Object) run



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/argos/soap_command.rb', line 147

def run
  begin
    @soap = Argos::Soap.new(param)
    
    @result = nil
    
    case param[:operation]
    when :getCsv
      @result = soap.getCsv 
    when :getPlatformList
      @result = soap.getPlatformList
    when :getKml
      @result = soap.getKml
    when :getObsCsv
      @result = soap.getObsCsv
    when :getObsXml
      @result = soap.getObsXml
    when :getStreamXml
      @result = soap.getStreamXml
    when :getXml
      @result = soap.getXml
    when :getXsd
      @result = soap.getXsd
    when :operations
      @result = soap.operations
    when :platforms
      @result = soap.platforms
    when :programs
      @result = soap.programs
    when :services
      @result = soap.services
    else
      raise ArgumentError, "Unspported operation: #{param[:operation]}"  
    end
    puts output.to_s
    
  rescue NodataException
    log.debug output
    exit(true)
  rescue => e
    STDERR.write output
    exit(false)
  end

end