argos-ruby 1.1.2 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Mjc1YTlhYTAwYTA4ZGE4MmYyZGFkYmUwNGNhNDE3MDNkYTA4MDdjNQ==
4
+ MmM0NDJiNWVjNDNjMWRhYTI4MmNjYWY2NTQ5ZTAwOWQwMjY5YTFjNA==
5
5
  data.tar.gz: !binary |-
6
- YjQzNDA1MDlkZjkyMWZlYTAwZWQ3NTVjODNhNjk5ZDI3MDZhOThiOA==
6
+ MzBiY2Q2MzYyOGU2NmY3NTNjMjE3MDhlNzYzMjk4YTNjODc2MDU4Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTcxM2NmZTdmYmU4MGZiOTRiYmM2MjM3NmE5NmJjMmFlOGNlYzVlNTgwYmEy
10
- NDQ3OTBkZTViZDk2MTJlMDc4NjA4NWE3OTMzYmIzN2ZhZDYwMjIyN2QyZWIy
11
- MjE2NThhY2RlZTM3Njg1MjkyMThlNDliYmVkYzgzZmMzZjU0MTQ=
9
+ MmM4ZmI1N2EzMzAxODhhZWE4NTk1MmMyYTAyNGM4ZDNkZWZiOWI4YTRiNDg5
10
+ MTc3OTdlYTkyMmY2NGJhMTk1OWFlMDc4OTEyYjA4MTMzNzI3OWFlNTEyYWM0
11
+ MjcyMjNjNTAyNzQxMDAwOTZkNTVmMzJmZmZhMWM3ZWZjZGZhYzk=
12
12
  data.tar.gz: !binary |-
13
- NmMyNzcwMDE0MjA3NTFhZjNkYzcyNjQyMDJhYjcxZmY4OTI3ZWQ3NGJmZWRj
14
- MTczZDQwODE0Njg2OTE2ZjIxOTlkODFjMjdkZGIwM2VhYzRmNzg0MDIyODNk
15
- YzE1NDkzZDUzMDc5N2EzOTUwYjQzNWZmMjY4M2VmNmZmODA4NzE=
13
+ MDcyMTZkMmYyNDVkOTdmZDY5YTBhZDk4MjkzZDc5NWRkNTY1ZTMwZWVlZTMz
14
+ OGQ2ZThiMDhiYWNmYjViNjhhZjk4YTA2YTkwYzc5OGVlYTczYmQ1YzdjZDQ4
15
+ OWYyM2E4M2IyMTNiNzI4ZDk2YWM1ODVlNTQ1MTAzYzBhZjU3NmE=
data/lib/argos/soap.rb CHANGED
@@ -21,19 +21,19 @@ module Argos
21
21
  # A "simple" Soap client for Argos-system satellite tracking webservice
22
22
  # http://wanderingbarque.com/nonintersecting/2006/11/15/the-s-stands-for-simple/
23
23
 
24
- # client [Savon]
24
+ # client [Savon] (version 3)
25
25
  # request [String] Soap:Envelope (XML request body)
26
26
  # response [Savon::Response]
27
27
  # operation [Savon::Operation]
28
+ # log [Logger]
28
29
  # xml [String] (Extracted, inner) XML
29
- # filter FIXME
30
+ # filter
30
31
  # platformId [String] Comma-separated list of platforms
31
32
  # programNumber [String] Comma-separated list of programs
32
33
  # nbDaysFromNow
33
34
  # period
34
- attr_accessor :client, :request, :response, :operation, :xml, :filter,
35
+ attr_accessor :client, :request, :response, :operation, :log, :xml, :filter,
35
36
  :platformId, :programNumber, :nbDaysFromNow, :period
36
-
37
37
  # username [String]
38
38
  # password [String]
39
39
  attr_writer :username, :password
@@ -78,7 +78,7 @@ module Argos
78
78
  end
79
79
  end
80
80
  end
81
-
81
+
82
82
  # Build baseRequest Hash
83
83
  # The service requires programNumber or PlatformId, but if you do not provide any,
84
84
  # this method will call the service (@see #programs) and get the current user's programs
@@ -92,11 +92,11 @@ module Argos
92
92
  if @programNumber.nil? and @platformId.nil?
93
93
  # Fetch all programs if neither is provided
94
94
  baseRequest[:programNumber] = programs.map {|p|p.to_s}.join(",")
95
- elsif @programNumber =~ /\d+/ and @platformId =~ /\d+/
96
- raise "Cannot provide both programNumber and platformId"
97
- elsif @programNumber =~ /\d+/
95
+ elsif @programNumber.to_s =~ /\d+/ and @platformId.to_s =~ /\d+/
96
+ baseRequest[:platformId] = @platformId # ignores programNumber
97
+ elsif @programNumber.to_s =~ /\d+/
98
98
  baseRequest[:programNumber] = @programNumber
99
- elsif @platformId =~ /\d+/
99
+ elsif @platformId.to_s =~ /\d+/
100
100
  baseRequest[:platformId] = @platformId
101
101
  end
102
102
 
@@ -112,13 +112,14 @@ module Argos
112
112
  baseRequest[:period] = @period
113
113
  end
114
114
 
115
- baseRequest = baseRequest.merge({
115
+ #baseRequest = baseRequest.merge({
116
+ # @todo
116
117
  #<xs:element minOccurs="0" name="referenceDate" type="tns:referenceDateType"/>
117
118
  #<xs:element minOccurs="0" name="locClass" type="xs:string"/>
118
119
  #<xs:element minOccurs="0" name="geographicArea" type="xs:string"/>
119
120
  #<xs:element minOccurs="0" name="compression" type="xs:int"/>
120
121
  #<xs:element minOccurs="0" name="mostRecentPassages" type="xs:boolean"/>
121
- })
122
+ #})
122
123
  baseRequest
123
124
 
124
125
  end
@@ -231,17 +232,19 @@ module Argos
231
232
 
232
233
  # Platforms: array of platformId integers
233
234
  # @return [Array] of [Integer]
234
- def platforms(programNumber=nil)
235
+ def platforms
235
236
  platforms = []
236
237
 
237
238
  platformListPrograms = getPlatformList["data"]["program"]
238
239
 
239
- if programNumber.to_s =~ /\d+/
240
- platformListPrograms.select! {|p| p["programNumber"].to_i == programNumber.to_i }
240
+ if @programNumber.to_s =~ /\d+/
241
+ platformListPrograms.select! {|p| p["programNumber"].to_i == @programNumber.to_i }
241
242
  end
243
+
242
244
  platformListPrograms.each do |program|
243
245
  platforms += program["platform"].map {|p| p["platformId"].to_i}
244
246
  end
247
+
245
248
  platforms
246
249
  end
247
250
 
@@ -268,7 +271,11 @@ module Argos
268
271
 
269
272
  # @return [String]
270
273
  def request
271
- operation.build
274
+ if operation.nil?
275
+ nil
276
+ else
277
+ operation.build
278
+ end
272
279
  end
273
280
 
274
281
  # @return [Hash] {"DixService":{"ports":{"DixServicePort":{"type":"http://schemas.xmlsoap.org/wsdl/soap12/","location":"http://ws-argos.cls.fr/argosDws/services/DixService"}}}}
@@ -332,15 +339,15 @@ module Argos
332
339
  ng = Nokogiri.XML(xml)
333
340
  ng.xpath("/data/errors/error").each do | error |
334
341
  if error.key?("code")
335
- case error["code"]
336
- when "4"
342
+ case error["code"].to_i
343
+ when 4
337
344
  raise NodataException
338
345
  end
339
346
  #<error code="2">max response reached</error>
340
- #<errors><error code="9">start date upper than end date</error></errors>
341
-
342
- else
343
- raise error
347
+ #<error code="3">authentification error</error>
348
+ #<error code="9">start date upper than end date</error>
349
+ else
350
+ raise Exception, error
344
351
  end
345
352
  end
346
353
 
@@ -1,21 +1,21 @@
1
- require "optparse"
1
+ require "optparse"
2
2
  require "net/http"
3
3
  require "csv"
4
4
 
5
5
  module Argos
6
-
7
6
  # argos-soap command
8
7
  #
9
8
  # On success, data is pumped to STDOUT, on faults/errors to STDERR
9
+ #
10
10
  # Examples:
11
11
  # $ argos-soap --operation getXml
12
- # $ argos-soap -o getXml --startDate="2014-03-10T00:00:00Z" --endDate="2014-03-10T23:59:59.999Z" --log-level=1
13
- # $ argos-soap -o getXml --startDate="`date --date=yesterday -I`T00:00:00Z" --endDate="`date --date=yesterday -I`T23:59:59.999Z" --username=**** --password=***** > /my/argos/xml/archive/`date -I --date=yesterday`.xml
12
+ # $ argos-soap -o getXml --startDate="2014-03-10T00:00:00Z" --endDate="2014-03-10T23:59:59.999Z" --log-level=0
13
+ # $ argos-soap -o getXml --date="`date --date=yesterday -I` --username=**** --password=***** > /my/argos/xml/archive/`date -I --date=yesterday`.xml
14
14
  class SoapCommand
15
15
 
16
16
  CMD = "argos-soap"
17
17
 
18
- PARAM = { format: :json, wsdl: Argos::Soap::WSDL }
18
+ PARAM = { format: :json, wsdl: Argos::Soap::WSDL, level: 1 }
19
19
 
20
20
  def self.run(argv=ARGV)
21
21
  begin
@@ -40,11 +40,16 @@ module Argos
40
40
 
41
41
  opts.banner = "#{CMD} operation [options]\n"
42
42
 
43
- opts.on("--debug", "Debug (alias for --log-level=0") do
43
+ opts.on("--debug", "Debug (alias for --log-level=0)") do
44
44
  @param[:level] = Logger::DEBUG
45
45
  end
46
46
 
47
- # --date shorthand for 1 day startDate endDate
47
+ # --date shorthand for 1 day period
48
+ opts.on("--date=isodate", "Set period to one day") do |isodate|
49
+ startDate = Time.parse(isodate+"T00:00:00Z").iso8601
50
+ endDate = Time.parse(isodate+"T23:59:59.999Z").iso8601
51
+ @param[:period] = { startDate: startDate, endDate: endDate }
52
+ end
48
53
 
49
54
  opts.on("--format=format", "-f=format", "{ json | xml | text | raw }") do |format|
50
55
  @param[:format] = format.to_sym
@@ -111,17 +116,28 @@ module Argos
111
116
  @param[:password] = password
112
117
  end
113
118
  end
119
+
120
+ opts.on("--download=archive", "Download") do |archive|
121
+ @param[:archive] = archive
122
+ end
114
123
 
115
124
  end
116
125
  option_parser.parse!
117
126
 
127
+ @log = Logger.new(STDERR)
128
+ @log.level = param[:level].to_i
129
+
130
+ if not @param[:archive].nil?
131
+ Argos::Download.download(param[:username], param[:password], param[:archive], log)
132
+ exit(true)
133
+ end
134
+
118
135
  if operation.nil?
119
136
  STDOUT.write option_parser.help
120
137
  exit(false)
121
138
  end
122
139
 
123
- @log = Logger.new(STDERR)
124
- @log.level = param[:level].to_i
140
+
125
141
  end
126
142
 
127
143
  def debug?
@@ -154,7 +170,7 @@ module Argos
154
170
  when :operations
155
171
  @result = soap.operations
156
172
  when :platforms
157
- @result = soap.platforms(param[:programNumber])
173
+ @result = soap.platforms
158
174
  when :programs
159
175
  @result = soap.programs
160
176
  when :services
@@ -162,12 +178,14 @@ module Argos
162
178
  else
163
179
  raise ArgumentError, "Unspported operation: #{param[:operation]}"
164
180
  end
165
- STDOUT.write output
181
+ puts output
166
182
 
167
183
  rescue NodataException
168
184
  log.debug output
185
+ exit(true)
169
186
  rescue => e
170
187
  STDERR.write output
188
+ exit(false)
171
189
  end
172
190
 
173
191
  end
@@ -178,7 +196,9 @@ module Argos
178
196
 
179
197
  if debug?
180
198
  log.debug "#{CMD} param: #{param.to_json}"
181
- log.debug "$ curl -XPOST #{Argos::Soap::URI} -d'#{soap.request}' -H \"Content-Type: application/soap+xml\""
199
+ unless soap.request.nil?
200
+ log.debug "$ curl -XPOST #{Argos::Soap::URI} -d'#{soap.request}' -H \"Content-Type: application/soap+xml\""
201
+ end
182
202
  end
183
203
 
184
204
  if result.is_a? Savon::Response
data/lib/argos.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "bundler/setup"
2
2
  require "bigdecimal"
3
3
  require "date"
4
- require "time" # for iso8601
4
+ require "time" # for #iso8601
5
5
  require "digest/sha1"
6
6
  require "json"
7
7
  require "logger"
@@ -12,9 +12,9 @@ require_relative "argos/ascii"
12
12
  require_relative "argos/ds"
13
13
  require_relative "argos/diag"
14
14
  require_relative "argos/soap"
15
- #require_relative "argos/download"
15
+ require_relative "argos/download"
16
16
 
17
- # Argos library containg
17
+ # [Argos](http://www.argos-system.org) satellite tracking data tools
18
18
  # * Parsers for Argos legacy ASCII files (DS/DAT and DIAG files)
19
19
  # * Soap web service client and Argos XML download tool
20
20
  #
@@ -25,7 +25,7 @@ require_relative "argos/soap"
25
25
  #
26
26
  # For information about Argos, see: http://www.argos-system.org
27
27
  module Argos
28
- VERSION = "1.1.2"
28
+ VERSION = "1.1.3"
29
29
 
30
30
  def self.library_version
31
31
  "argos-ruby-#{VERSION}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: argos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Espen Egeland
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-17 00:00:00.000000000 Z
12
+ date: 2014-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec