ckan 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.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .*.sw?
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :gemcutter
2
+
3
+ # Specify your gem's dependencies in ckan.gemspec
4
+ gemspec
@@ -0,0 +1,72 @@
1
+ = CKAN
2
+
3
+ * http://github.com/apohllo/CKAN
4
+
5
+ = DESCRIPTION
6
+
7
+ 'CKAN' is a Ruby client of the Comprehensive Knowledge Archive Network.
8
+
9
+ = FEATURES/PROBLEMS
10
+
11
+ * The project is in pre-alpha state.
12
+ * CKAN packages REST API wrapper.
13
+ * CKAN resources class.
14
+ * Query API for CKAN packages.
15
+
16
+ = SYNOPSIS
17
+
18
+ 'CKAN' is a Ruby client for the Comprehensive Knowledge Archive Network. It
19
+ provides an object oriented interface for the repository based on the REST API
20
+ of CKAN.
21
+
22
+ = INSTALL
23
+
24
+ The gem is available at rubygems.org, so you can install it with:
25
+
26
+ $ gem install ckan
27
+
28
+ = BASIC USAGE
29
+
30
+ require 'ckan'
31
+
32
+ # get all CKAN packages
33
+ packages = CKAN::Package.find
34
+
35
+ # query for CKAN packages
36
+ packages = CKAN::Package.find(:tags => ["lod", "government"], :groups => "lodcloud")
37
+
38
+ # get the name of the package (this is a lazy call to the REST API)
39
+ packages.first.name
40
+
41
+ # get the resources of the package
42
+ packages.first.resources
43
+
44
+ == LICENSE:
45
+
46
+ (The MIT License)
47
+
48
+ Copyright (c) 2010 Aleksander Pohl
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining
51
+ a copy of this software and associated documentation files (the
52
+ 'Software'), to deal in the Software without restriction, including
53
+ without limitation the rights to use, copy, modify, merge, publish,
54
+ distribute, sublicense, and/or sell copies of the Software, and to
55
+ permit persons to whom the Software is furnished to do so, subject to
56
+ the following conditions:
57
+
58
+ The above copyright notice and this permission notice shall be
59
+ included in all copies or substantial portions of the Software.
60
+
61
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
62
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
63
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
64
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
65
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
66
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
67
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
+
69
+ == FEEDBACK
70
+
71
+ * mailto:apohllo@o2.pl
72
+
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path("../lib/ckan/version", __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "ckan"
6
+ s.version = CKAN::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Aleksander Pohl"]
9
+ s.email = ["apohllo@o2.pl"]
10
+ s.homepage = "http://github.com/apohllo/ckan"
11
+ s.summary = "Ruby Client for Comprehensive Knowledge Archive Network"
12
+ s.description = "Ruby Client for Comprehensive Knowledge Archive Network. Allows for querying the CKAN repository using REST API"
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "ckan"
16
+
17
+ s.add_development_dependency "bundler", ">= 1.0.0"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
21
+ s.require_path = 'lib'
22
+ s.rdoc_options = ["--main", "README.txt"]
23
+ s.has_rdoc = true
24
+ s.extra_rdoc_files = ["README.txt"]
25
+ end
@@ -0,0 +1,10 @@
1
+ module CKAN
2
+ API_BASE = "http://ckan.net/api/2/"
3
+ end
4
+
5
+ require 'open-uri'
6
+ require 'json'
7
+ require 'ckan/model'
8
+ require 'ckan/package'
9
+ require 'ckan/resource'
10
+ require 'ckan/version'
@@ -0,0 +1,44 @@
1
+ module CKAN
2
+ class Model
3
+ protected
4
+
5
+ def read_lazy_data
6
+ unless @lazy_data_read
7
+ self.class.read_remote_json_data(self.class.site + "/" + self.id).
8
+ each do |name,value|
9
+ self.instance_variable_set("@"+name,value)
10
+ end
11
+ @lazy_data_read = true
12
+ end
13
+ end
14
+
15
+ def self.site=(address)
16
+ @site = address
17
+ end
18
+
19
+ def self.site
20
+ @site
21
+ end
22
+
23
+ def self.search=(address)
24
+ @search = address
25
+ end
26
+
27
+ def self.search
28
+ @search
29
+ end
30
+
31
+ def self.read_remote_json_data(address)
32
+ JSON.parse(open(address).read)
33
+ end
34
+
35
+ def self.lazy_reader(*names)
36
+ names.each do |name|
37
+ define_method(name) do
38
+ read_lazy_data
39
+ instance_variable_get("@" + name.to_s)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,51 @@
1
+ module CKAN
2
+ class Package < Model
3
+ self.site = API_BASE + "rest/package"
4
+ self.search = API_BASE + "search/package"
5
+
6
+ attr_reader :id
7
+ lazy_reader :name, :title, :url
8
+
9
+ def initialize(id)
10
+ @id = id
11
+ end
12
+
13
+ def self.find(options=nil)
14
+ if options.nil?
15
+ @all_packages ||= read_remote_json_data(self.site).map{|id| Package.get(id)}
16
+ else
17
+ query = "?"
18
+ query += options.to_a.
19
+ map{|k,v| v.is_a?(Array) ? v.map{|vv| "#{k}=#{URI.encode(vv)}"}.join("&") :
20
+ "#{k}=#{URI.encode(v)}"}.join("&")
21
+ puts query
22
+ result = read_remote_json_data(self.search + query)
23
+ if result["count"] != result["results"].size
24
+ query += "&offset=#{result["results"].size}&limit=#{result["count"] + result["results"].size}"
25
+ result["results"] += read_remote_json_data(self.search + query)["results"]
26
+ end
27
+
28
+ result["results"].map{|id| Package.get(id)}
29
+ end
30
+ end
31
+
32
+ def resources
33
+ read_lazy_data
34
+ @mapped_resources ||= @resources.
35
+ map{|r| Resource.new(r["url"],r["format"],r["description"],r["hash"])}
36
+ end
37
+
38
+ def to_s
39
+ "CKAN::Package[#{@id}]"
40
+ end
41
+
42
+ protected
43
+ def self.get(id)
44
+ @package_map ||= {}
45
+ unless @package_map[id]
46
+ @package_map[id] = Package.new(id)
47
+ end
48
+ @package_map[id]
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,9 @@
1
+ module CKAN
2
+ class Resource
3
+ attr_reader :url, :format, :description, :hash
4
+
5
+ def initialize(url, format, description, hash)
6
+ @url, @format, @description, @hash = url, format, description, hash
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module CKAN
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ckan
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Aleksander Pohl
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-21 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: bundler
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 0
31
+ - 0
32
+ version: 1.0.0
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Ruby Client for Comprehensive Knowledge Archive Network. Allows for querying the CKAN repository using REST API
36
+ email:
37
+ - apohllo@o2.pl
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README.txt
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - README.txt
48
+ - Rakefile
49
+ - ckan.gemspec
50
+ - lib/ckan.rb
51
+ - lib/ckan/model.rb
52
+ - lib/ckan/package.rb
53
+ - lib/ckan/resource.rb
54
+ - lib/ckan/version.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/apohllo/ckan
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options:
61
+ - --main
62
+ - README.txt
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ segments:
79
+ - 1
80
+ - 3
81
+ - 6
82
+ version: 1.3.6
83
+ requirements: []
84
+
85
+ rubyforge_project: ckan
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Ruby Client for Comprehensive Knowledge Archive Network
90
+ test_files: []
91
+