mobile-rb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 777fe45773a38c5f6c05d93abab97ed3beabb849
4
+ data.tar.gz: 41e3459e11d0f0c0d72fdcc51582c2b44a7fe758
5
+ SHA512:
6
+ metadata.gz: a55eda09ff9011f0833a9ccfb4cef78daecfdc00238c114c666f859e6590af239bcedc42e581b3862ea98797adc6b173993a51fb3dd87b06684ff37be7e6934e
7
+ data.tar.gz: a242edc5517ad691812a0d4458219cab9fc3c86ecdd5c630019645e461e48046b29a6e6ff6d2f964b98cd450687d4e77679ffa0eca48207a2611c4871a63b54e
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mobile.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Dominik Schmidt
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,27 @@
1
+ # mobile-rb
2
+
3
+ Mobile-rb is a new ruby wrapper for the german Mobile.de API. Tests included (but need to be extended).
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ gem install mobile-rb
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ client = Mobile.configure do |config|
15
+ config.username = "your_username"
16
+ config.password = "your_password"
17
+ # config.api_version = "1.0.0" # Optional
18
+ end
19
+ ```
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it ( https://github.com/[my-github-username]/mobile/fork )
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,55 @@
1
+ require 'httparty'
2
+ require 'multi_xml'
3
+ require 'ap'
4
+
5
+ module Mobile
6
+ def self.configure(&block)
7
+ Mobile::Client.new(&block)
8
+ end
9
+
10
+ class Client
11
+ include HTTParty
12
+ base_uri 'http://services.mobile.de'
13
+
14
+ attr_writer :username, :password, :api_version
15
+ attr_accessor :username, :password, :api_version
16
+
17
+ def initialize(&block)
18
+ yield(self)
19
+ self.api_version = '1.0.0' if self.api_version.nil?
20
+ self
21
+ end
22
+
23
+
24
+ def ads(options={})
25
+ request('get', '/ad/search', options)['result']
26
+ end
27
+
28
+ def ad(id, options={})
29
+ request('get', "/ad/#{id}", options)['ad']
30
+ end
31
+
32
+ def configured?
33
+ raise Mobile::MissingConfig, "Either username or password is not set in configuration block. Please fix this." unless !username.nil? && !password.nil?
34
+ !username.nil? && !password.nil?
35
+ end
36
+
37
+ private
38
+
39
+ def request(method, path, opts={})
40
+ opts.merge!({ headers: headers, basic_auth: auth })
41
+ response = self.class.get("/#{api_version}#{path}", opts)
42
+ parsed_body = MultiXml.parse(response.body)
43
+ raise Mobile::BadRequest, "Your search query can not be processed. Unfortunately, we can't provide more details but at least we don't reply with an internal server error any more. Maybe it helps to specify a search parameter which is not boolean or numeric. We will improve this in the future." if parsed_body.nil?
44
+ parsed_body
45
+ end
46
+
47
+ def headers
48
+ { "Accept-Language" => "de" }
49
+ end
50
+
51
+ def auth
52
+ { username: self.username, password: self.password }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,8 @@
1
+ module Mobile
2
+ class MissingConfig < StandardError
3
+ end
4
+ class AdNotFound < StandardError
5
+ end
6
+ class BadRequest < StandardError
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Mobile
2
+ VERSION = "0.0.1"
3
+ end
data/lib/mobile.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "mobile/version"
2
+ require "mobile/error"
3
+ require "mobile/client"
data/mobile.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mobile/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mobile-rb"
8
+ spec.version = Mobile::VERSION
9
+ spec.authors = ["Dominik Schmidt"]
10
+ spec.email = ["visualcake@me.com"]
11
+ spec.description = 'A Ruby interface to the Mobile.de API.'
12
+ spec.summary = spec.description
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = %w(lib)
20
+
21
+ spec.add_runtime_dependency "multi_xml", "~> 0.5.5"
22
+ spec.add_runtime_dependency "httparty", "~> 0.13.3"
23
+
24
+ spec.add_development_dependency "rspec", "~> 2.6"
25
+ spec.add_development_dependency "bundler", "~> 1.7"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "awesome_print", "~> 1.6.1"
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'awesome_print'
2
+ require 'spec_helper'
3
+
4
+ describe Mobile::Client do
5
+ before(:each) do
6
+ @client = Mobile.configure { |config|
7
+ config.username = ENV['MOBILE_USER']
8
+ config.password = ENV['MOBILE_PW']
9
+ config.api_version = "1.0.0"
10
+ }
11
+ end
12
+
13
+ it 'should be configured' do
14
+ expect(@client.configured?).to be_truthy
15
+ end
16
+
17
+ it 'should search for all vehicles' do
18
+ expect(@client.ads().size).to be >= 1
19
+ end
20
+
21
+ it 'should search for one vehicles' do
22
+ expect(@client.ad(203908080).size).to be >= 1
23
+ end
24
+ end
@@ -0,0 +1,2 @@
1
+ require 'mobile'
2
+ require 'mobile/client'
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mobile-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Schmidt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_xml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: httparty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.13.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.13.3
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.1
97
+ description: A Ruby interface to the Mobile.de API.
98
+ email:
99
+ - visualcake@me.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - lib/mobile.rb
111
+ - lib/mobile/client.rb
112
+ - lib/mobile/error.rb
113
+ - lib/mobile/version.rb
114
+ - mobile.gemspec
115
+ - spec/mobile_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: ''
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.0.14
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: A Ruby interface to the Mobile.de API.
141
+ test_files:
142
+ - spec/mobile_spec.rb
143
+ - spec/spec_helper.rb