museumkaart 0.0.1

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: bbdfd60d8c796856e4079221d417857d78885743
4
+ data.tar.gz: 1ba9d62d9ce98c86246f862c262e891aba537b14
5
+ SHA512:
6
+ metadata.gz: aff6d7523739b467d5a3f2e9d3ac08416679845a7682bbb34b6a360623a11570e46adacbfbff5b4aab7cb0a10d46c679caab9ffcc87e97da1f03f9d0a7ba0945
7
+ data.tar.gz: fade54bb7119581f078c55c5e470a26669ead35a71438aa5506dc1d12c4578a7d45af1e2339046e4c8ed9ce960e27d61c679b39731b62d1764cff74c5341696a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in museumkaart.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Henk Meijer
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,46 @@
1
+ # Museumkaart
2
+
3
+ Query the museumjaarkaart database for museums in The Netherlands. The is fetched from a xml feed from museumjaarkaart.nl.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'museumkaart'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install museumkaart
18
+
19
+ ## Usage
20
+
21
+ For now, this gem has limitited search functionality:
22
+
23
+ - location based (latitude, longitude, distance)
24
+ - query based
25
+ - combined
26
+
27
+ ## Examples
28
+
29
+ ```ruby
30
+ # Find van Gogh museum
31
+ @museums = Museumkaart.search(keyword: "Van Gogh Museum")
32
+
33
+ # Find museums in a certain area
34
+ @museums = Museumkaart.search(latitude: "52.222687", latitude: "5.483039", distance: 3)
35
+
36
+ @museums.first # => #<Museumkaart::Museum:0x007fe1532d9178 @id=10455, @title="NIJKERK", @sub_title="Museum Nijkerk", @description="x", @detail_url="/museum/Museum+Nijkerk/Museum+Nijkerk.aspx">
37
+
38
+ ```
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,69 @@
1
+ module Museumkaart
2
+
3
+ class Museum
4
+ attr_accessor :id, :title, :sub_title, :image_url, :description, :detail_url, :is_participant
5
+
6
+ # MuseumId:
7
+ # - type: Edm.Int32
8
+ # content: '337'
9
+ # Title:
10
+ # - HENGELO
11
+ # SubTitle:
12
+ # - Historisch Museum Hengelo
13
+ # Description:
14
+ # - 'Historisch Museum Hengelo brengt de cultuur en de geschiedenis van Hengelo
15
+ # in beeld. In een ruim 100 jaar oude patricirswoning toont het een gevarieerde
16
+ # collectie: van kunst tot gebruiksvoorwerpen.'
17
+ # ImageUrl:
18
+ # - //cdn.museum.nl/cards/240x135/musnieuw/historischmuseumhengelo.jpg
19
+ # HasPromotions:
20
+ # - type: Edm.Boolean
21
+ # content: 'false'
22
+ # IsPromotion:
23
+ # - type: Edm.Boolean
24
+ # content: 'false'
25
+ # IsParticipant:
26
+ # - type: Edm.Boolean
27
+ # content: 'true'
28
+ # EndDate:
29
+ # - type: Edm.DateTime
30
+ # 'null': 'true'
31
+ # DetailUrl:
32
+ # - /museum/Historisch+Museum+Hengelo/Historisch+Museum+Hengelo.aspx
33
+ # MagazineTheme:
34
+ # - 'null': 'true'
35
+ # MagazineThemeTitle:
36
+ # - 'null': 'true'
37
+ # City:
38
+ # - 'null': 'true'
39
+ # Address:
40
+ # - 'null': 'true'
41
+ # Type:
42
+ # - type: Edm.Int32
43
+ # content: '1'
44
+ # IsKidsproof:
45
+ # - type: Edm.Boolean
46
+ # 'null': 'true'
47
+
48
+
49
+
50
+ #
51
+ # Initializer to transform a +Hash+ into an Tip object
52
+ #
53
+ # @param [Hash] args
54
+
55
+
56
+ def initialize(args=nil)
57
+ return if args.nil?
58
+ args.each do |k,v|
59
+ instance_variable_set("@#{k}", v) unless v.nil?
60
+ end
61
+ # typecast_attrs
62
+ end
63
+
64
+ def full_title
65
+ "#{title} | #{sub_title}"
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Museumkaart
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,68 @@
1
+ require "museumkaart/version"
2
+
3
+ # Libraries
4
+ require 'open-uri'
5
+ require 'net/http'
6
+ require 'json'
7
+ require 'nokogiri'
8
+ require 'xmlsimple'
9
+
10
+ # Files
11
+ require "museumkaart/museum"
12
+
13
+ #
14
+ # Museumkaart Module
15
+ #
16
+
17
+ module Museumkaart
18
+
19
+ BASE_URL = "http://www.museumkaart.nl/zoekresultaten.aspx"
20
+ # keyword=
21
+ # longitude=5.483039
22
+ # lattitude=52.222687
23
+ # distance=1
24
+ # province=
25
+ # startdate=
26
+ # enddate=
27
+ # lastChance=0
28
+ # filters=
29
+ # lFacilities=
30
+ # mFacilities=
31
+ # type=-1
32
+ # card=1
33
+ # cityName=
34
+ # datetype=maakt%20niet%20uit
35
+ # kidsProof=0
36
+
37
+ def self.search(keyword: "", longitude: "", latitude: "", distance: 10, card: 1, city: "")
38
+ url = "http://www.museumkaart.nl/Services/SchatkamerService.svc/GetSearchResult?&start=0&count=100&keyword=%27#{CGI::escape(keyword)}%27&city=%27#{city}%27&longitude=%27#{longitude}%27&lattitude=%27#{latitude}%27&distance=%27#{distance}%27&provinceFilter=%27%27&startdate=%27%27&enddate=%27%27&lastChance=0&filters=%27%27&lFacilities=%27%27&mFacilities=%27%27&type=-1&card=1&cityName=%27%27&theme=&allMembers=&kidsProof=0"
39
+
40
+ list = []
41
+ doc = Nokogiri::XML(open(url))
42
+ # puts doc.root.search("entry").count
43
+ doc.root.search("entry").each do |entry|
44
+ # puts entry.to_xml
45
+ h = XmlSimple.xml_in(entry.to_xml.to_s.gsub("m:", "").gsub("d:", ""))
46
+ # {"id"=>["http://www.museumkaart.nl/Services/SchatkamerService.svc/SchatkamerKaartSet(311)"], "title"=>[{"type"=>"text"}], "updated"=>["2015-09-17T08:11:14Z"], "author"=>[{"name"=>[{}]}], "link"=>[{"rel"=>"edit", "title"=>"TreasuryCard", "href"=>"SchatkamerKaartSet(311)"}], "category"=>[{"term"=>"Museumvereniging.Shared.Treasury.TreasuryCard", "scheme"=>"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"}],
47
+ # "content"=>{"type"=>"application/xml", "properties"=>[{"Id"=>[{"type"=>"Edm.Int32", "content"=>"311"}], "MuseumId"=>[{"type"=>"Edm.Int32", "content"=>"337"}], "Title"=>["HENGELO"], "SubTitle"=>["Historisch Museum Hengelo"], "Description"=>["Historisch Museum Hengelo brengt de cultuur en de geschiedenis van Hengelo in beeld. In een ruim 100 jaar oude patricirswoning toont het een gevarieerde collectie: van kunst tot gebruiksvoorwerpen."], "ImageUrl"=>["//cdn.museum.nl/cards/240x135/musnieuw/historischmuseumhengelo.jpg"], "HasPromotions"=>[{"type"=>"Edm.Boolean", "content"=>"false"}], "IsPromotion"=>[{"type"=>"Edm.Boolean", "content"=>"false"}], "IsParticipant"=>[{"type"=>"Edm.Boolean", "content"=>"true"}], "EndDate"=>[{"type"=>"Edm.DateTime", "null"=>"true"}], "DetailUrl"=>["/museum/Historisch+Museum+Hengelo/Historisch+Museum+Hengelo.aspx"], "MagazineTheme"=>[{"null"=>"true"}], "MagazineThemeTitle"=>[{"null"=>"true"}], "City"=>[{"null"=>"true"}], "Address"=>[{"null"=>"true"}], "Type"=>[{"type"=>"Edm.Int32", "content"=>"1"}], "IsKidsproof"=>[{"type"=>"Edm.Boolean", "null"=>"true"}]}]}}
48
+ content = h["content"]["properties"].first
49
+ m = Museumkaart::Museum.new(
50
+ id: h["id"].first.split("(").last.split(")").first.to_i,
51
+ title: content["Title"].first,
52
+ sub_title: content["SubTitle"].first,
53
+ description: content["Description"].first,
54
+ detail_url: content["DetailUrl"].first
55
+ # :detail_url, :is_participant
56
+ # image_url:,
57
+ # description:,
58
+ # detail_url:,
59
+ # is_participant:,
60
+ # detail_url:,
61
+ )
62
+ list << m
63
+ end
64
+ return list
65
+ end
66
+
67
+ # Your code goes here...
68
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'museumkaart/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "museumkaart"
8
+ spec.version = Museumkaart::VERSION
9
+ spec.authors = ["Henk Meijer"]
10
+ spec.email = ["meijerhenk@gmail.com"]
11
+ spec.description = %q{Ruby gem for querying museums in the museumjaarkaart database}
12
+ spec.summary = %q{Ruby gem for querying museums in the museumjaarkaart database}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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 = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "fakeweb"
26
+
27
+ spec.add_dependency "nokogiri"
28
+ spec.add_dependency "xml-simple"
29
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Museumkaart do
4
+
5
+ describe ".search" do
6
+
7
+ context "keyword" do
8
+ before(:all) do
9
+ VCR.use_cassette("search for nijkerk") do
10
+ @results = Museumkaart.search(keyword: "historisch")
11
+ end
12
+
13
+ end
14
+
15
+ it "makes http request" do
16
+ expect(@results.count).to be > 0
17
+ end
18
+
19
+ it "returns museum type objects" do
20
+ expect(@results.first).to be_kind_of(Museumkaart::Museum)
21
+ end
22
+
23
+ it "has a name" do
24
+ expect(@results.first.full_title).to be_kind_of(String)
25
+ expect(@results.first.full_title).to include("|")
26
+ end
27
+ it "has a detail URL" do
28
+ expect(@results.first.detail_url).to be_kind_of(String)
29
+ expect(@results.first.detail_url).to include("/")
30
+ end
31
+ end
32
+
33
+ context "location" do
34
+ before(:all) do
35
+ VCR.use_cassette("search for location") do
36
+ @results = Museumkaart.search(keyword: "Museum Nijkerk", latitude: "52.222687", latitude: "5.483039", distance: 3)
37
+ end
38
+ end
39
+
40
+ it "returns 1 object" do
41
+ expect(@results.count).to be 1
42
+ end
43
+
44
+ it "returns museum type objects" do
45
+ expect(@results.first.full_title).to include "Museum Nijkerk"
46
+ puts @results.first.inspect
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,37 @@
1
+ require "bundler"
2
+ Bundler.setup(:default, :development)
3
+
4
+ # require 'simplecov'
5
+ # require 'coveralls'
6
+
7
+ # Coveralls.wear!
8
+ # SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ # SimpleCov::Formatter::HTMLFormatter,
10
+ # Coveralls::SimpleCov::Formatter
11
+ # ]
12
+ # SimpleCov.start
13
+
14
+ require 'rubygems'
15
+ require 'bundler/setup'
16
+ require 'vcr'
17
+ require 'cgi'
18
+ require 'museumkaart'
19
+
20
+ VCR.configure do |c|
21
+ c.cassette_library_dir = 'spec/vcr_cassettes'
22
+ c.hook_into :fakeweb
23
+ c.register_request_matcher :ignore_query_param_ordering do |r1, r2|
24
+ uri1 = URI(r1.uri)
25
+ uri2 = URI(r2.uri)
26
+
27
+ uri1.scheme == uri2.scheme &&
28
+ uri1.host == uri2.host &&
29
+ uri1.path == uri2.path &&
30
+ CGI.parse(uri1.query) == CGI.parse(uri2.query)
31
+ end
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ config.order = "random"
36
+ # config.filter_run :focus => true
37
+ end
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://www.museumkaart.nl/Services/SchatkamerService.svc/GetSearchResult?&start=0&count=100&keyword=%27Museum+Nijkerk%27&city=%27%27&longitude=%27%27&lattitude=%275.483039%27&distance=%273%27&provinceFilter=%27%27&startdate=%27%27&enddate=%27%27&lastChance=0&filters=%27%27&lFacilities=%27%27&mFacilities=%27%27&type=-1&card=1&cityName=%27%27&theme=&allMembers=&kidsProof=0
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ accept-encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ accept:
13
+ - '*/*'
14
+ user-agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ cache-control:
22
+ - private
23
+ content-length:
24
+ - '2113'
25
+ content-type:
26
+ - application/atom+xml;charset=utf-8
27
+ server:
28
+ - Microsoft-IIS/7.5
29
+ set-cookie:
30
+ - .ASPXANONYMOUS=qGq_4r8n0QEkAAAAMjFkYzA3YTItYzhjNi00YjY2LWFlNTYtYThmNjhmMjhjYmU50;
31
+ expires=Wed, 25-Nov-2015 20:28:46 GMT; path=/; HttpOnly
32
+ - ASP.NET_SessionId=saawo0z4ujcqwz1ta5x4o2kx; path=/; HttpOnly
33
+ dataserviceversion:
34
+ - 1.0;
35
+ x-aspnet-version:
36
+ - 4.0.30319
37
+ x-powered-by:
38
+ - ASP.NET
39
+ date:
40
+ - Thu, 17 Sep 2015 09:48:46 GMT
41
+ body:
42
+ encoding: UTF-8
43
+ string: "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\r\n<feed
44
+ xml:base=\"http://www.museumkaart.nl/Services/SchatkamerService.svc/\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\"
45
+ xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\"
46
+ xmlns=\"http://www.w3.org/2005/Atom\">\r\n <title type=\"text\">GetSearchResult</title>\r\n
47
+ \ <id>http://www.museumkaart.nl/Services/SchatkamerService.svc/GetSearchResult</id>\r\n
48
+ \ <updated>2015-09-17T09:48:46Z</updated>\r\n <link rel=\"self\" title=\"GetSearchResult\"
49
+ href=\"GetSearchResult\" />\r\n <entry>\r\n <id>http://www.museumkaart.nl/Services/SchatkamerService.svc/SchatkamerKaartSet(10455)</id>\r\n
50
+ \ <title type=\"text\"></title>\r\n <updated>2015-09-17T09:48:46Z</updated>\r\n
51
+ \ <author>\r\n <name />\r\n </author>\r\n <link rel=\"edit\"
52
+ title=\"TreasuryCard\" href=\"SchatkamerKaartSet(10455)\" />\r\n <category
53
+ term=\"Museumvereniging.Shared.Treasury.TreasuryCard\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\"
54
+ />\r\n <content type=\"application/xml\">\r\n <m:properties>\r\n <d:Id
55
+ m:type=\"Edm.Int32\">10455</d:Id>\r\n <d:MuseumId m:type=\"Edm.Int32\">1163</d:MuseumId>\r\n
56
+ \ <d:Title>NIJKERK</d:Title>\r\n <d:SubTitle>Museum Nijkerk</d:SubTitle>\r\n
57
+ \ <d:Description>x</d:Description>\r\n <d:ImageUrl>//cdn.museum.nl/cards/240x135/af48bd59-ad30-4f11-8ede-cd2518aa4e24\\Venenstraat
58
+ 16 foto Gerrit van de Veen.jpg</d:ImageUrl>\r\n <d:HasPromotions m:type=\"Edm.Boolean\">false</d:HasPromotions>\r\n
59
+ \ <d:IsPromotion m:type=\"Edm.Boolean\">false</d:IsPromotion>\r\n <d:IsParticipant
60
+ m:type=\"Edm.Boolean\">true</d:IsParticipant>\r\n <d:EndDate m:type=\"Edm.DateTime\"
61
+ m:null=\"true\" />\r\n <d:DetailUrl>/museum/Museum+Nijkerk/Museum+Nijkerk.aspx</d:DetailUrl>\r\n
62
+ \ <d:MagazineTheme m:null=\"true\" />\r\n <d:MagazineThemeTitle
63
+ m:null=\"true\" />\r\n <d:City m:null=\"true\" />\r\n <d:Address
64
+ m:null=\"true\" />\r\n <d:Type m:type=\"Edm.Int32\">1</d:Type>\r\n
65
+ \ <d:IsKidsproof m:type=\"Edm.Boolean\" m:null=\"true\" />\r\n </m:properties>\r\n
66
+ \ </content>\r\n </entry>\r\n</feed>"
67
+ http_version: '1.1'
68
+ recorded_at: Thu, 17 Sep 2015 09:48:44 GMT
69
+ recorded_with: VCR 2.9.3