justimmo_client 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +15 -0
  3. data/.gitignore +15 -0
  4. data/.gitlab-ci.yml +67 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +90 -0
  7. data/.ruby-version +1 -0
  8. data/Gemfile +21 -0
  9. data/LICENSE +21 -0
  10. data/README.md +72 -0
  11. data/Rakefile +14 -0
  12. data/bin/console +21 -0
  13. data/bin/setup +8 -0
  14. data/examples/client.rb +16 -0
  15. data/justimmo_client.gemspec +41 -0
  16. data/lib/justimmo_client/api/v1/models/city.rb +16 -0
  17. data/lib/justimmo_client/api/v1/models/country.rb +44 -0
  18. data/lib/justimmo_client/api/v1/models/employee.rb +45 -0
  19. data/lib/justimmo_client/api/v1/models/federal_state.rb +15 -0
  20. data/lib/justimmo_client/api/v1/models/file.rb +64 -0
  21. data/lib/justimmo_client/api/v1/models/geo_location.rb +47 -0
  22. data/lib/justimmo_client/api/v1/models/image.rb +10 -0
  23. data/lib/justimmo_client/api/v1/models/justimmo_base.rb +15 -0
  24. data/lib/justimmo_client/api/v1/models/realty.rb +82 -0
  25. data/lib/justimmo_client/api/v1/models/realty_area.rb +49 -0
  26. data/lib/justimmo_client/api/v1/models/realty_category.rb +13 -0
  27. data/lib/justimmo_client/api/v1/models/realty_marketing.rb +12 -0
  28. data/lib/justimmo_client/api/v1/models/realty_price.rb +94 -0
  29. data/lib/justimmo_client/api/v1/models/realty_room_count.rb +35 -0
  30. data/lib/justimmo_client/api/v1/models/realty_type.rb +12 -0
  31. data/lib/justimmo_client/api/v1/models/realty_usage.rb +24 -0
  32. data/lib/justimmo_client/api/v1/models/region.rb +12 -0
  33. data/lib/justimmo_client/api/v1/representers/json/attachment_image_representer.rb +16 -0
  34. data/lib/justimmo_client/api/v1/representers/json/attachment_representer.rb +15 -0
  35. data/lib/justimmo_client/api/v1/representers/json/contact_representer.rb +30 -0
  36. data/lib/justimmo_client/api/v1/representers/json/justimmo_representer.rb +13 -0
  37. data/lib/justimmo_client/api/v1/representers/json/location_representer.rb +14 -0
  38. data/lib/justimmo_client/api/v1/representers/json/realty_category_representer.rb +21 -0
  39. data/lib/justimmo_client/api/v1/representers/json/realty_detail_representer.rb +69 -0
  40. data/lib/justimmo_client/api/v1/representers/json.rb +10 -0
  41. data/lib/justimmo_client/api/v1/representers/xml/city_representer.rb +18 -0
  42. data/lib/justimmo_client/api/v1/representers/xml/contact_representer.rb +15 -0
  43. data/lib/justimmo_client/api/v1/representers/xml/country_representer.rb +15 -0
  44. data/lib/justimmo_client/api/v1/representers/xml/employee_list_representer.rb +15 -0
  45. data/lib/justimmo_client/api/v1/representers/xml/employee_representer.rb +46 -0
  46. data/lib/justimmo_client/api/v1/representers/xml/federal_state_representer.rb +17 -0
  47. data/lib/justimmo_client/api/v1/representers/xml/geo_location_representer.rb +24 -0
  48. data/lib/justimmo_client/api/v1/representers/xml/justimmo_representer.rb +13 -0
  49. data/lib/justimmo_client/api/v1/representers/xml/realty_area_representer.rb +28 -0
  50. data/lib/justimmo_client/api/v1/representers/xml/realty_category_representer.rb +15 -0
  51. data/lib/justimmo_client/api/v1/representers/xml/realty_detail_representer.rb +92 -0
  52. data/lib/justimmo_client/api/v1/representers/xml/realty_list_representer.rb +85 -0
  53. data/lib/justimmo_client/api/v1/representers/xml/realty_price_representer.rb +53 -0
  54. data/lib/justimmo_client/api/v1/representers/xml/realty_representer.rb +32 -0
  55. data/lib/justimmo_client/api/v1/representers/xml/realty_room_count_representer.rb +22 -0
  56. data/lib/justimmo_client/api/v1/representers/xml/realty_type_representer.rb +14 -0
  57. data/lib/justimmo_client/api/v1/representers/xml/region_representer.rb +14 -0
  58. data/lib/justimmo_client/api/v1/representers/xml.rb +11 -0
  59. data/lib/justimmo_client/api/v1/requests/employee_request.rb +24 -0
  60. data/lib/justimmo_client/api/v1/requests/justimmo_request.rb +64 -0
  61. data/lib/justimmo_client/api/v1/requests/realty_request.rb +209 -0
  62. data/lib/justimmo_client/api/v1.rb +16 -0
  63. data/lib/justimmo_client/autoload.rb +17 -0
  64. data/lib/justimmo_client/core/caching.rb +55 -0
  65. data/lib/justimmo_client/core/config.rb +46 -0
  66. data/lib/justimmo_client/core/logging.rb +46 -0
  67. data/lib/justimmo_client/core/utils.rb +38 -0
  68. data/lib/justimmo_client/employee.rb +39 -0
  69. data/lib/justimmo_client/errors.rb +58 -0
  70. data/lib/justimmo_client/misc.rb +10 -0
  71. data/lib/justimmo_client/option_parser.rb +107 -0
  72. data/lib/justimmo_client/realty.rb +150 -0
  73. data/lib/justimmo_client/version.rb +5 -0
  74. data/lib/justimmo_client.rb +22 -0
  75. data/notes.md +19 -0
  76. metadata +271 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf4841e8f104288f8d22c0658455dd0531a404e6
4
+ data.tar.gz: a6a20249b890e68531a598770d3ed4d2a4520e23
5
+ SHA512:
6
+ metadata.gz: 32bc0852bc996494f3f1ac4890b9dff42a2cec38f47659a58952907fb5d6daa2b709cceda9dc45bb1ef085671a9b77ce8b987b3c7780c0cbe6cc7ca24f7414f4
7
+ data.tar.gz: c2d6ab04e7d7cf93bee94415722f32e4c3691753228d3b5a9ed8d8a5d72dddd9afbcec4eb9a673999a43f230596211451a2cf7b53699392491c5361ec44b0ca7
data/.editorconfig ADDED
@@ -0,0 +1,15 @@
1
+ # for the sake of sanity
2
+
3
+ # topmost editorconfig file
4
+ root = true
5
+
6
+ # always use Unix-style newlines,
7
+ # use 4 spaces for indentation
8
+ # and use UTF-8 encoding
9
+ [*]
10
+ indent_style = space
11
+ indent_size = 2
12
+ end_of_line = lf
13
+ charset = utf-8
14
+ trim_trailing_whitespace = true
15
+ insert_final_newline = true
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ .env*
15
+ coverage
data/.gitlab-ci.yml ADDED
@@ -0,0 +1,67 @@
1
+ .test_job: &test_job
2
+ environment: testing
3
+ cache:
4
+ paths:
5
+ - cache/bundler
6
+ before_script:
7
+ - bundle install --without development -j $(nproc) --path=cache/bundler
8
+ tags:
9
+ - ruby
10
+
11
+ .test_job_2_3: &test_job_2_3
12
+ image: 'ruby:2.3'
13
+ <<: *test_job
14
+
15
+ .test_job_2_4: &test_job_2_4
16
+ image: 'ruby:2.4'
17
+ <<: *test_job
18
+
19
+ test:rubocop_2_3:
20
+ <<: *test_job_2_3
21
+ script: bundle exec rubocop
22
+ only:
23
+ - dev
24
+
25
+ test:rubocop_2_4:
26
+ <<: *test_job_2_4
27
+ script: bundle exec rubocop
28
+ only:
29
+ - dev
30
+
31
+ test:rspec_2_3:
32
+ <<: *test_job_2_3
33
+ script: bundle exec rspec
34
+ artifacts:
35
+ paths:
36
+ - coverage/
37
+
38
+ test:rspec_2_4:
39
+ <<: *test_job_2_4
40
+ script: bundle exec rspec
41
+ artifacts:
42
+ paths:
43
+ - coverage/
44
+
45
+ pages:
46
+ stage: deploy
47
+ dependencies:
48
+ - test:rspec_2_4
49
+ script:
50
+ - mv coverage/ public/
51
+ artifacts:
52
+ paths:
53
+ - public
54
+ expire_in: 30 days
55
+ only:
56
+ - master
57
+
58
+ deploy:rubygems:
59
+ stage: deploy
60
+ dependencies:
61
+ - test:rspec_2_4
62
+ before_script:
63
+ - gem install dpl
64
+ script:
65
+ - dpl --provider=rubygems --api-key=$RUBYGEMS_API_KEY
66
+ only:
67
+ - tags
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,90 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ DisabledByDefault: true
4
+ Exclude:
5
+ - bin/**
6
+ - cache/**/*
7
+ - spec/**/*
8
+
9
+ # [Layout]
10
+ Layout/CaseIndentation:
11
+ Enabled: true
12
+
13
+ Layout/CommentIndentation:
14
+ Enabled: true
15
+
16
+ Layout/EmptyLines:
17
+ Enabled: true
18
+
19
+ Layout/EmptyLinesAroundClassBody:
20
+ Enabled: true
21
+
22
+ Layout/EmptyLinesAroundMethodBody:
23
+ Enabled: true
24
+
25
+ Layout/EmptyLinesAroundModuleBody:
26
+ Enabled: true
27
+
28
+ Layout/IndentationConsistency:
29
+ Enabled: true
30
+
31
+ Layout/IndentationWidth:
32
+ Enabled: true
33
+
34
+ Layout/SpaceAfterColon:
35
+ Enabled: true
36
+
37
+ Layout/SpaceAfterComma:
38
+ Enabled: true
39
+
40
+ Layout/SpaceAroundEqualsInParameterDefault:
41
+ Enabled: true
42
+
43
+ Layout/SpaceAroundOperators:
44
+ Enabled: true
45
+
46
+ Layout/SpaceInsideBlockBraces:
47
+ Enabled: true
48
+
49
+ Layout/SpaceInsideHashLiteralBraces:
50
+ Enabled: true
51
+
52
+ Layout/SpaceInsideParens:
53
+ Enabled: true
54
+
55
+ Layout/Tab:
56
+ Enabled: true
57
+
58
+ Layout/TrailingBlankLines:
59
+ Enabled: true
60
+
61
+ Layout/TrailingWhitespace:
62
+ Enabled: true
63
+
64
+ # [Lint]
65
+ Lint/EndAlignment:
66
+ Enabled: true
67
+ EnforcedStyleAlignWith: variable
68
+
69
+ Lint/RequireParentheses:
70
+ Enabled: true
71
+
72
+ # [Style]
73
+ Style/AndOr:
74
+ Enabled: true
75
+
76
+ Style/BracesAroundHashParameters:
77
+ Enabled: true
78
+
79
+ Style/HashSyntax:
80
+ Enabled: true
81
+
82
+ Style/MethodDefParentheses:
83
+ Enabled: true
84
+
85
+ Style/StringLiterals:
86
+ Enabled: true
87
+ EnforcedStyle: double_quotes
88
+
89
+ Style/UnneededPercentQ:
90
+ Enabled: true
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.3
data/Gemfile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ group :test do
6
+ # Test coverage reporting
7
+ gem "simplecov", require: false
8
+ end
9
+
10
+ group :test, :development do
11
+ gem "rspec", "~> 3.0"
12
+ gem "rubocop", "~> 0.48"
13
+ gem "dotenv"
14
+ end
15
+
16
+ group :development do
17
+ gem "yard"
18
+ gem "pry"
19
+ end
20
+
21
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Patrick Auernig
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,72 @@
1
+ [![build status](https://gitlab.com/exacting/justimmo-client-ruby/badges/master/build.svg)](https://gitlab.com/exacting/justimmo-client-ruby/pipelines)
2
+ [![coverage report](https://gitlab.com/exacting/justimmo-client-ruby/badges/master/coverage.svg)](https://valeth.gitlab.io/justimmo-client-ruby)
3
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7cfe6c9965214c439470cc0a480e0e49)](https://www.codacy.com/app/exacting/justimmo-client-ruby?utm_source=gitlab.com&amp;utm_medium=referral&amp;utm_content=exacting/justimmo-client-ruby&amp;utm_campaign=Badge_Grade)
4
+ [![Inline docs](http://inch-ci.org/github/exacting/justimmo-client-ruby.svg?branch=master)](http://inch-ci.org/github/exacting/justimmo-client-ruby)
5
+
6
+
7
+ # Justimmo Client
8
+
9
+ Ruby client for the [Justimmo](http://www.justimmo.at) [REST API](http://api-docs.justimmo.at/api/index.html).
10
+
11
+ ## Dependencies
12
+
13
+ * Ruby 2.3+
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem "justimmo_client"
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle install
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install justimmo_client
30
+
31
+
32
+ ## Usage Example (Rails)
33
+
34
+ > config/initializers/justimmo.rb
35
+ ```ruby
36
+ JustimmoClient.configure do |config|
37
+ config.username = "your-username"
38
+ config.password = "your_password"
39
+ config.cache = ActiveSupport::Cache.lookup_store(:memory_store)
40
+ end
41
+ ```
42
+
43
+ ---
44
+
45
+ > app/controllers/realty_controller.rb
46
+ ```ruby
47
+ class RealtyController < ApplicationController
48
+ def index
49
+ @realties = JustimmoClient::Realty.list(zip_code: 6020, limit: 5)
50
+ end
51
+ end
52
+ ```
53
+
54
+ For other examples see [examples](examples/).
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies.
59
+ Then, put your user credentials into a `.env` file and run `rake spec` to run the tests.
60
+ You can also run `bin/console` for an interactive prompt that will allow you to experiment.
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and merge requests are welcome on
65
+ [GitLab](https://gitlab.com/exacting/justimmo-client-ruby).
66
+
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
71
+
72
+ Check the [LICENSE](LICENSE) file for more information.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
6
+ require "yard"
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ RuboCop::RakeTask.new(:rubocop)
10
+ YARD::Rake::YardocTask.new(:doc)
11
+
12
+ task default: :test
13
+
14
+ task test: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "justimmo_client"
5
+ require "dotenv"
6
+
7
+ Dotenv.load
8
+
9
+ JustimmoClient.configure do |config|
10
+ config.username = ENV['JUSTIMMO_USERNAME']
11
+ config.password = ENV['JUSTIMMO_PASSWORD']
12
+ config.debug = ENV['DEBUG']
13
+ end
14
+
15
+ begin
16
+ require 'pry'
17
+ Pry.start
18
+ rescue LoadError
19
+ require 'irb'
20
+ IRB.start(__FILE__)
21
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "dotenv"
4
+ require "pp"
5
+ require "active_support/cache"
6
+ require "justimmo_client"
7
+
8
+ Dotenv.load
9
+
10
+ JustimmoClient.configure do |config|
11
+ config.username = ENV["JUSTIMMO_USERNAME"]
12
+ config.password = ENV["JUSTIMMO_PASSWORD"]
13
+ config.cache = ActiveSupport::Cache.lookup_store(:memory_store)
14
+ end
15
+
16
+ pp JustimmoClient::Realty.list(zip_code: 6800, limit: 5)
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ # coding: utf-8
3
+
4
+ lib = File.expand_path("../lib", __FILE__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require "justimmo_client/version"
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = "justimmo_client"
10
+ spec.version = JustimmoClient::VERSION
11
+ spec.author = "Patrick Auernig"
12
+ spec.email = "patrick.auernig@mykolab.com"
13
+ spec.license = "MIT"
14
+ spec.summary = "API client for Justimmo"
15
+ spec.homepage = "https://gitlab.com/exacting/justimmo-client-ruby"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+
27
+ # requests
28
+ spec.add_dependency "rest-client", "~> 2"
29
+ spec.add_dependency "retriable", "~> 2.0"
30
+
31
+ # parsing
32
+ spec.add_dependency "nokogiri", "~> 1.7"
33
+ spec.add_dependency "multi_json"
34
+ spec.add_dependency "representable", "~> 3.0"
35
+
36
+ # models
37
+ spec.add_dependency "virtus"
38
+ spec.add_dependency "activesupport", "~> 5.1"
39
+ spec.add_dependency "iso_country_codes"
40
+ spec.add_dependency "monetize"
41
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ class City < JustimmoBase
5
+ # @!group Attributes
6
+
7
+ # @!macro [attach] attribute
8
+ # @return [$2]
9
+ attribute :id, Integer
10
+ attribute :country_id, Integer
11
+ attribute :region_id, Integer
12
+ attribute :zip_code, Integer
13
+ attribute :location, String
14
+ attribute :federal_state_id, Integer
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "iso_country_codes"
4
+
5
+ module JustimmoClient::V1
6
+ class Country < JustimmoBase
7
+ # @!group Attributes
8
+
9
+ # @!macro [attach] attribute
10
+ # @return [$2]
11
+ attribute :id, Integer
12
+ attribute :alpha2, String
13
+ attribute :alpha2, String
14
+
15
+ # @!group Instance Method Summary
16
+
17
+ def initialize(**options)
18
+ super(options)
19
+ @country = nil
20
+ end
21
+
22
+ def alpha2=(code)
23
+ @country ||= IsoCountryCodes.find(code)
24
+ @alpha2 ||= @country.alpha2
25
+ end
26
+
27
+ def alpha3=(code)
28
+ @country ||= IsoCountryCodes.find(code)
29
+ @alpha3 ||= @country.alpha3
30
+ end
31
+
32
+ def name
33
+ @country&.name
34
+ end
35
+
36
+ def to_s
37
+ @country&.name || ""
38
+ end
39
+
40
+ def inspect
41
+ "#<#{self.class} #{self}>"
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ class Employee < JustimmoBase
5
+ # @!group Attributes
6
+
7
+ # @!macro [attach] attribute
8
+ # @return [$2]
9
+ attribute :id, Integer
10
+ attribute :number, Integer
11
+ attribute :email, String
12
+ attribute :phone, String
13
+ attribute :mobile, String
14
+ attribute :fax, String
15
+ attribute :last_name, String
16
+ attribute :first_name, String
17
+ attribute :salutation, String
18
+ attribute :company, String
19
+ attribute :street, String
20
+ attribute :zip_code, Integer
21
+ attribute :location, String
22
+ attribute :email_feedback, String
23
+ attribute :website, String
24
+ attribute :picture, Image
25
+ attribute :attachment, Image
26
+ attribute :position, String
27
+
28
+ # @!group Instance Method Summary
29
+
30
+ def full_name(surname_first: false, with_salutation: true)
31
+ name = [first_name, last_name]
32
+ name.reverse! if surname_first
33
+ name.unshift(salutation) if with_salutation
34
+ name.compact.join(" ")
35
+ end
36
+
37
+ def to_s
38
+ full_name
39
+ end
40
+
41
+ def inspect
42
+ "#<#{self.class} #{self}>"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ class FederalState < JustimmoBase
5
+ # @!group Attributes
6
+
7
+ # @!macro [attach] attribute
8
+ # @return [$2]
9
+ attribute :id, Integer
10
+ attribute :name, String
11
+ attribute :country_id, Integer
12
+ attribute :fips, String
13
+ attribute :iso, String
14
+ end
15
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ class File < JustimmoBase
5
+ BASE_URL = "https://files.justimmo.at/public"
6
+
7
+ # @!group Attributes
8
+
9
+ # @!macro [attach] attribute
10
+ # @return [$2]
11
+ attribute :title, String
12
+ attribute :category, Symbol
13
+ attribute :origin, Symbol
14
+ attribute :type, Symbol
15
+ attribute :name, String
16
+ attribute :format, String
17
+
18
+ # @!group Instance Method Summary
19
+
20
+ def initialize(**options)
21
+ super(options)
22
+ @settings = []
23
+ end
24
+
25
+ def category=(cat)
26
+ @category =
27
+ case cat
28
+ when "BILD" then :image
29
+ when "TITELBILD" then :title_image
30
+ else nil
31
+ end
32
+ end
33
+
34
+ def origin=(orig)
35
+ @origin = orig&.downcase&.to_sym
36
+ end
37
+
38
+ def get(setting = nil)
39
+ return nil if @default.nil? || @settings.empty?
40
+ setting = (@settings.include?(setting) ? setting : @default)
41
+ "#{BASE_URL}/#{@type}/#{setting}/#{@name}"
42
+ end
43
+
44
+ alias [] get
45
+
46
+ def add_url(url, default: nil)
47
+ uri_path = URI.parse(url).path
48
+ @name ||= ::File.basename(uri_path)
49
+ @format ||= ::File.extname(@name)
50
+ @settings << ::URI.parse(url).path.split("/")[-2].to_sym
51
+ @default = default || @settings.last
52
+ end
53
+
54
+ alias path= add_url
55
+
56
+ def to_s
57
+ get
58
+ end
59
+
60
+ def inspect
61
+ "#<#{self.class} #{self}>"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "iso_country_codes"
4
+
5
+ module JustimmoClient::V1
6
+ class GeoLocation < JustimmoBase
7
+ # @!group Attributes
8
+
9
+ # @!macro [attach] attribute
10
+ # @return [$2]
11
+ attribute :proximity, String
12
+ attribute :federal_state, String
13
+ attribute :country, String
14
+ attribute :zip_code, Integer
15
+ attribute :latitude, Float
16
+ attribute :longitude, Float
17
+ attribute :location, String
18
+ attribute :proximity, String
19
+ attribute :floor, Integer
20
+
21
+ # @!group Instance Method Summary
22
+
23
+ def country=(iso3)
24
+ @country = IsoCountryCodes.find(iso3)
25
+ end
26
+
27
+ def floor=(flr)
28
+ @floor = flr.to_i
29
+ end
30
+
31
+ def to_s
32
+ ["#{zip_code} #{location}", federal_state, country&.name].compact.join(", ")
33
+ end
34
+
35
+ def inspect
36
+ "#<#{self.class} #{self}>"
37
+ end
38
+
39
+ def to_h
40
+ { latitude: latitude, longitude: longitude }
41
+ end
42
+
43
+ def to_a
44
+ [latitude, longitude]
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JustimmoClient::V1
4
+ class Image < File
5
+ def initialize(**options)
6
+ super(options)
7
+ @type = :pic
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "virtus"
4
+
5
+ module JustimmoClient::V1
6
+ # @api private
7
+ class JustimmoBase
8
+ include JustimmoClient::Logging
9
+
10
+ # :nodoc:
11
+ include Virtus.model do |mod|
12
+ mod.coercer.config.string.boolean_map = { "0" => false, "1" => true }
13
+ end
14
+ end
15
+ end