hoolp 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f14bfecb716fefcfaf5cb01859e9b04e60e50fe
4
+ data.tar.gz: 8f23a12e52109128fdbefc2f7eee353a0252f69c
5
+ SHA512:
6
+ metadata.gz: a0d5c4b1883731eab4256ad3c5d1faee1d78a9885515f0068e47a3ba88ff3369c17b1af59fd471a4710b6cabffa05b30f82b75f5517682ede755ed6ab479e305
7
+ data.tar.gz: 48f1c5825ebe5dac6de0e9ac050e6075f345aa6d6e06be4944d3b72e18bbc680323bc068e69850119151e1b6a8f5d21807742ecd45c7f8c5127e15dee7f9195b
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # hooolp-client
2
+ Hooolp API client
data/lib/hoolp.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "hashie"
2
+ require "httparty"
3
+ require "uri"
4
+
5
+ require "hoolp/version"
6
+ require "hoolp/api_error"
7
+ require "hoolp/client"
8
+ require "hoolp/resource/event"
9
+
10
+ module Hoolp
11
+ def new(api_key:)
12
+ @client = Client.new(api_key: api_key)
13
+ end
14
+ module_function :new
15
+
16
+ def events(location_id:)
17
+ @client.events(location_id: location_id)
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ module Hoolp
2
+ class ApiError < StandardError
3
+ def initialize(response_body)
4
+ super(response_body.fetch("error"))
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ module Hoolp
2
+ class Client
3
+ include HTTParty
4
+
5
+ USER_AGENT = "ASK HELMUT Hooolp Client #{VERSION}".freeze
6
+ DEFAULT_OPTIONS = {
7
+ base_url: "http://api2.hooolp.com"
8
+ }.freeze
9
+
10
+ attr_accessor :options
11
+
12
+ headers("User-Agent" => USER_AGENT)
13
+
14
+ def initialize(options)
15
+ store_options(options)
16
+ end
17
+
18
+ def events(location_id:)
19
+ query = construct_query_arguments(
20
+ resource: "events",
21
+ options: "locations=#{location_id}&ctr=DE"
22
+ )
23
+
24
+ response = self.class.get(
25
+ *query
26
+ )
27
+
28
+ result = JSON.parse(response.body)
29
+
30
+ raise ApiError(result) if !result.is_a?(Array) && result.key?("error")
31
+
32
+ result.map do |item|
33
+ Resource::Event.new(item.fetch("event"))
34
+ end
35
+ end
36
+
37
+ def base_url
38
+ @options.fetch(:base_url)
39
+ end
40
+
41
+ def api_key
42
+ @options.fetch(:api_key)
43
+ end
44
+
45
+ private
46
+
47
+ def store_options(options)
48
+ @options ||= DEFAULT_OPTIONS.dup
49
+ @options.merge!(options)
50
+ end
51
+
52
+ def handle_response(&block)
53
+ response = yield block
54
+ ResponseWrapper.new(response)
55
+ end
56
+
57
+ def construct_query_arguments(resource:, options:)
58
+ [
59
+ "#{base_url}/#{resource}.json?#{options}&key=#{api_key}"
60
+ ]
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,39 @@
1
+ require "byebug"
2
+
3
+ module Hoolp
4
+ module Resource
5
+ class Event
6
+ MEDIA_BASE_URL = "http://hooolp.com".freeze
7
+
8
+ def initialize(raw_event)
9
+ @raw_event = raw_event
10
+ end
11
+
12
+ def id
13
+ @raw_event.fetch("id")
14
+ end
15
+
16
+ def starts_at
17
+ Time.parse(@raw_event.fetch("startDate")).utc
18
+ end
19
+
20
+ def title
21
+ @raw_event.fetch("acts")
22
+ end
23
+
24
+ def description
25
+ @raw_event.fetch("addText")
26
+ end
27
+
28
+ def image_urls
29
+ @raw_event.fetch("bandFotos").map do |image_path|
30
+ [MEDIA_BASE_URL, image_path].join
31
+ end
32
+ end
33
+
34
+ def genres
35
+ @raw_event.fetch("genresCsv").split(",").map(&:strip)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Hoolp
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hoolp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Niels Hoffmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ description: Simple wrapper to request data from the Hooolp API.
28
+ email:
29
+ - niels@askhelmut.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - README.md
35
+ - lib/hoolp.rb
36
+ - lib/hoolp/api_error.rb
37
+ - lib/hoolp/client.rb
38
+ - lib/hoolp/resource/event.rb
39
+ - lib/hoolp/version.rb
40
+ homepage: https://www.askhelmut.com
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.3.5
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 2.5.1
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: A wrapper for the Hooolp API.
64
+ test_files: []
65
+ has_rdoc: