leipzig 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
- Copyright (c) 2012 Mario Behrendt
1
+ (The MIT License)
2
2
 
3
- MIT License
3
+ Copyright (c) 2012 Mario Behrendt info@mario-behrendt.de
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -29,9 +29,7 @@ Simply create a new instance of the client using your api key and call one of th
29
29
  ```ruby
30
30
  require 'leipzig'
31
31
 
32
- key = 'my-key'
33
-
34
- client = Leipzig::Mediahandbook.new(key)
32
+ client = Leipzig::Mediahandbook.new('my-key')
35
33
 
36
34
  companies = client.find_companies(:postcode => '04103')
37
35
  branches = client.find_branches(:limit => 5)
@@ -48,9 +46,13 @@ client.find_companies(:limit => 10).first.name
48
46
  # ==> First company's name
49
47
  ```
50
48
 
51
- ## Note
49
+ Besides `Mediahandbook` there are also classes for `District` and `Calendar` which are used the same way. Again, see
50
+ link above for more information about params and structures. Calls could look as follows:
52
51
 
53
- At the moment only the mediahandbook entries are supported.
52
+ ```ruby
53
+ Leipzig::Calendar.new(key).find_events
54
+ Leipzig::District.new(key).find_streets
55
+ ```
54
56
 
55
57
  ## Running the tests
56
58
 
@@ -59,16 +61,6 @@ $ bundle
59
61
  $ API_KEY='my-key' rake
60
62
  ```
61
63
 
62
- ## Contributing
63
-
64
- 1. Fork it
65
- 2. Create your feature branch
66
- 3. Write code and tests
67
- 4. Check tests
68
- 5. Commit your changes if tests pass
69
- 6. Push to the branch
70
- 7. Create new Pull Request
71
-
72
64
  ## Todo
73
65
 
74
66
  * Refactoring
@@ -9,6 +9,9 @@ module Leipzig
9
9
 
10
10
  attr_reader :api_key
11
11
 
12
+ # Constructor
13
+ #
14
+ # @param [String] API Key to use
12
15
  def initialize(api_key)
13
16
  @api_key = api_key
14
17
  @conditions = { :limit => 10, :name => 'leipzig', :api_key => @api_key }
@@ -17,10 +20,18 @@ module Leipzig
17
20
 
18
21
  private
19
22
 
23
+ # Returns hash of TYPES for instance
24
+ #
25
+ # @return [Hash] Available types
20
26
  def types
21
27
  self.singleton_class.const_get(:TYPES)
22
28
  end
23
29
 
30
+ # Generates URI and triggers API call
31
+ #
32
+ # @param [String] Type of resource to find
33
+ # @param [Hash] Conditions
34
+ # @return [Array] Result set of `request` method
24
35
  def find(type, conditions = {})
25
36
  raise "Type #{type} is invalid" unless types.include?(type.to_sym)
26
37
  uri = "#{API_URL}/#{resource}/#{type}"
@@ -32,10 +43,15 @@ module Leipzig
32
43
  request(uri, conditions)
33
44
  end
34
45
 
46
+ # Returns true if `conditions` hash includes non-keyword keys, hence search params
47
+ #
48
+ # @param [Hash] Conditions to check
49
+ # @return [Boolean] True if search param was found
35
50
  def has_search_param?(conditions)
36
51
  conditions.keys.select { |key| !KEYWORDS.include?(key) }.any?
37
52
  end
38
53
 
54
+ # Registers find_*-methods for each TYPE on current instance
39
55
  def register_methods
40
56
  types.each do |type|
41
57
  self.class.send(:define_method, "find_#{type}".to_sym) do |*args|
@@ -44,10 +60,19 @@ module Leipzig
44
60
  end
45
61
  end
46
62
 
63
+ # Returns reource name based on instance class name
64
+ # For instance "Leipzig::Mediahandbook" leads to "mediahandbook"
65
+ #
66
+ # @return [String] Resource name
47
67
  def resource
48
68
  self.class.to_s.split('::').last.downcase
49
69
  end
50
70
 
71
+ # Calls API and returns Array which contains OpenStructs if entries were found
72
+ #
73
+ # @param [String] URI to call
74
+ # @param [Hash] Conditions for call like limit, offset and search params
75
+ # @return [Array] List of found entries
51
76
  def request(uri, conditions)
52
77
  result = JSON.parse RestClient.get(uri, :params => @conditions.merge(conditions))
53
78
 
@@ -1,3 +1,3 @@
1
1
  module Leipzig
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: leipzig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -96,7 +96,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  segments:
98
98
  - 0
99
- hash: -953058203614356815
99
+ hash: 1076362203260376975
100
100
  required_rubygems_version: !ruby/object:Gem::Requirement
101
101
  none: false
102
102
  requirements:
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  segments:
107
107
  - 0
108
- hash: -953058203614356815
108
+ hash: 1076362203260376975
109
109
  requirements: []
110
110
  rubyforge_project:
111
111
  rubygems_version: 1.8.24