leipzig 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +75 -0
- data/Rakefile +11 -0
- data/leipzig.gemspec +22 -0
- data/lib/leipzig/client.rb +37 -0
- data/lib/leipzig/version.rb +3 -0
- data/lib/leipzig.rb +6 -0
- data/spec/leipzig/client_spec.rb +38 -0
- data/spec/leipzig/spec_helper.rb +0 -0
- data/spec/leipzig/version_spec.rb +7 -0
- metadata +115 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Mario Behrendt
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Leipzig
|
2
|
+
|
3
|
+
Tiny client for [API Leipzig](http://www.apileipzig.de)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem 'leipzig'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
$ gem install leipzig
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Simply create a new instance of the client using your api key and call one of the `find` methods:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'leipzig'
|
31
|
+
|
32
|
+
key = 'my-key'
|
33
|
+
|
34
|
+
client = Leipzig::Client.new(key)
|
35
|
+
|
36
|
+
companies = client.find_companies(:postcode => '04103')
|
37
|
+
branches = client.find_branches(:limit => 5)
|
38
|
+
people = client.find_people(:offset => 100)
|
39
|
+
```
|
40
|
+
|
41
|
+
All `find` methods except a hash of params which are used to change the result set. See [this link](http://www.apileipzig.de/wiki/show/allgemeineParameter) for more
|
42
|
+
information about available params.
|
43
|
+
|
44
|
+
## Note
|
45
|
+
|
46
|
+
At the moment only the mediahandbook entries are supported.
|
47
|
+
|
48
|
+
## Running the tests
|
49
|
+
|
50
|
+
```bash
|
51
|
+
$ bundle
|
52
|
+
$ API_KEY='my-key' rake
|
53
|
+
```
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch
|
59
|
+
3. Write code and tests
|
60
|
+
4. Check tests
|
61
|
+
5. Commit your changes if tests pass
|
62
|
+
6. Push to the branch
|
63
|
+
7. Create new Pull Request
|
64
|
+
|
65
|
+
## License
|
66
|
+
|
67
|
+
(The MIT License)
|
68
|
+
|
69
|
+
Copyright (c) 2012 Mario Behrendt info@mario-behrendt.de
|
70
|
+
|
71
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
72
|
+
|
73
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
74
|
+
|
75
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/leipzig.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/leipzig/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mario Behrendt"]
|
6
|
+
gem.email = ["info@mario-behrendt.de"]
|
7
|
+
gem.description = %q{Tiny client for API Leipzig}
|
8
|
+
gem.summary = %q{Tiny client for API Leipzig}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "leipzig"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Leipzig::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'rest-client'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'rake'
|
22
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
module Leipzig
|
6
|
+
class Client
|
7
|
+
TYPES = [:companies, :branches, :people]
|
8
|
+
API_URL = 'http://www.apileipzig.de/api/v1/mediahandbook/'
|
9
|
+
|
10
|
+
attr_reader :api_key
|
11
|
+
|
12
|
+
TYPES.each do |type|
|
13
|
+
define_method "find_#{type}" do |*args|
|
14
|
+
find(type, *args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(api_key)
|
19
|
+
@api_key = api_key
|
20
|
+
@options = { :limit => 10, :name => 'leipzig', :api_key => @api_key }
|
21
|
+
end
|
22
|
+
|
23
|
+
def find(type, conditions)
|
24
|
+
raise "Type #{type} is invalid" unless TYPES.include?(type.to_sym)
|
25
|
+
|
26
|
+
uri = "#{API_URL}#{type}/search"
|
27
|
+
|
28
|
+
result = JSON.parse(RestClient.get(uri, :params => @options.merge(conditions)))
|
29
|
+
|
30
|
+
if result.has_key? "error"
|
31
|
+
raise "Webservice returned error for uri '#{uri}': #{result['error']}"
|
32
|
+
end
|
33
|
+
|
34
|
+
result['data'].map { |entry| OpenStruct.new(entry) }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/leipzig.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'leipzig/client'
|
2
|
+
|
3
|
+
KEY = ENV['API_KEY']
|
4
|
+
LIMIT = 5
|
5
|
+
|
6
|
+
describe 'Client' do
|
7
|
+
let(:client) { Leipzig::Client.new(KEY) }
|
8
|
+
|
9
|
+
it 'returns given API key' do
|
10
|
+
client.api_key.should eq(KEY)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'reponds to all three mediahandbook types' do
|
14
|
+
client.should respond_to(:find_branches)
|
15
|
+
client.should respond_to(:find_companies)
|
16
|
+
client.should respond_to(:find_people)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'returns json representation of resource with default limit' do
|
20
|
+
data = client.find_companies(:limit => LIMIT)
|
21
|
+
data.should be_instance_of(Array)
|
22
|
+
data.size.should eq(LIMIT)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'takes search parameter into account' do
|
26
|
+
zip = '04319'
|
27
|
+
data = client.find_companies(:limit => 2, :postcode => zip)
|
28
|
+
data.map { |company| company.postcode.should eq(zip) }
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'raises exception if invalid key is used' do
|
32
|
+
lambda { Leipzig::Client.new('wrong').find_companies }.should raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'raises exception if undefined method is called' do
|
36
|
+
lambda { client.find_something }.should raise_error
|
37
|
+
end
|
38
|
+
end
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: leipzig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mario Behrendt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Tiny client for API Leipzig
|
63
|
+
email:
|
64
|
+
- info@mario-behrendt.de
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- leipzig.gemspec
|
76
|
+
- lib/leipzig.rb
|
77
|
+
- lib/leipzig/client.rb
|
78
|
+
- lib/leipzig/version.rb
|
79
|
+
- spec/leipzig/client_spec.rb
|
80
|
+
- spec/leipzig/spec_helper.rb
|
81
|
+
- spec/leipzig/version_spec.rb
|
82
|
+
homepage: ''
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: -1631967839568932202
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: -1631967839568932202
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.24
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Tiny client for API Leipzig
|
112
|
+
test_files:
|
113
|
+
- spec/leipzig/client_spec.rb
|
114
|
+
- spec/leipzig/spec_helper.rb
|
115
|
+
- spec/leipzig/version_spec.rb
|