reittiopas2 0.0.2 → 0.0.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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f61d78bc33cb927d5e288ba20c7f5b9385bf56a
4
- data.tar.gz: 9587070a1c875a2b75bb7ce4fb3714b1cd4fac9c
3
+ metadata.gz: b8b3c7b2da73211b4625740a06095a6b5311ac5c
4
+ data.tar.gz: 3da51d3fa7d8be313364e1f0ce4dab1619bdf26e
5
5
  SHA512:
6
- metadata.gz: 991f00ec596342b691c3988e33e4617ce27e2ed3fa2bdb798b245bca664addba83e20ce2c6ef5595d1543edebc3bda15904c451c81b786344894488c3c4690ea
7
- data.tar.gz: eff294c382393227a67e683dc15e6455b8173e94369910128ad1a724cd51198acae06eeb8d9d63f936208d45b3001f15f6bb372980d01cb94ebfe6b6f915afcf
6
+ metadata.gz: a5b9646c750f603ac549fa18769a65961aa3e8e3b577453700f98049d2262de4f759253937beb69a6fb1847e07f6f7db5c02c9c5c909ec9220d8740aa25bb45e
7
+ data.tar.gz: 9edc016afdc19c8daf25543f5f07da1b98e5753e260218012ab97213b6296e3a0fba61fe40f473ea7eb6d6dc5fbad09b02f2227ebe6d1aa4e90998b8b9aa3e2b
@@ -1,3 +1,5 @@
1
+ require 'reittiopas2/util'
2
+
1
3
  require 'addressable/uri'
2
4
  require 'json'
3
5
  require 'net/http'
@@ -32,7 +34,7 @@ class Connection
32
34
  # @return [Hash] the whatever data was requested from API, or Hash containing
33
35
  # key 'error' containing error message.
34
36
  def perform_query(query={})
35
- query = fix_arrays(query)
37
+ query = Util.convert_array_values(query)
36
38
  uri = Addressable::URI.parse(@base_url)
37
39
  uri.query_values = @base_query.merge(query)
38
40
 
@@ -51,38 +53,6 @@ class Connection
51
53
  {'error' => ex.class}
52
54
  end
53
55
 
54
-
55
- private
56
-
57
-
58
- # Reittiopas API wants arrays as values seperated with pipes. This method
59
- # checks query for arrays and converts them to API friendly versions.
60
- #
61
- # @param [Hash] query the query to be checked for arrays to convert.
62
- # @return [Hash] hash where arrays are converted to pipe presentation.
63
- def fix_arrays(query)
64
- retval = {}
65
- query.each do |key, val|
66
- if val.is_a? Array
67
- retval[key] = array_to_query_form(val)
68
- else
69
- retval[key] = val
70
- end
71
- end
72
- retval
73
- end
74
-
75
-
76
- def array_to_query_form(arr)
77
- raise(ArgumentError, "arr is not Array") unless arr.is_a? Array
78
-
79
- retval = ""
80
- arr.each do |val|
81
- retval << val << "|"
82
- end
83
-
84
- retval[0..-2] # Remove last pipe
85
- end
86
56
  end
87
57
 
88
58
  end
@@ -2,6 +2,23 @@ class Reittiopas2
2
2
 
3
3
  module Util
4
4
 
5
+ # Converts array values into string values containing array members joined
6
+ # by pipe ('|') characters.
7
+ #
8
+ # @param [Hash] a hash
9
+ # @return [Hash] a hash
10
+ def self.convert_array_values(hash)
11
+ result = hash.map do |key, value|
12
+ if value.is_a? Array
13
+ [key, value.join('|')]
14
+ else
15
+ [key, value]
16
+ end
17
+ end
18
+
19
+ Hash[result]
20
+ end
21
+
5
22
  def self.select_keys(hash, keys)
6
23
  hash.select do |key, value|
7
24
  keys.include? key
@@ -1,3 +1,3 @@
1
1
  class Reittiopas2
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/reittiopas2.gemspec CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{Reittiopas version 2 API library.}
8
8
  gem.summary = %q{Gem providing easy access to reittiopas version 2 API.}
9
9
  gem.homepage = "https://github.com/orva/reittiopas2"
10
+ gem.license = "MIT"
10
11
 
11
12
  gem.files = `git ls-files`.split($\)
12
13
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reittiopas2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iivari Äikäs
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-30 00:00:00.000000000 Z
12
+ date: 2013-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -137,7 +137,8 @@ files:
137
137
  - spec/routing_spec.rb
138
138
  - spec/spec_helper.rb
139
139
  homepage: https://github.com/orva/reittiopas2
140
- licenses: []
140
+ licenses:
141
+ - MIT
141
142
  metadata: {}
142
143
  post_install_message:
143
144
  rdoc_options: []