ppe_api 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ppe_api/constants_application.rb +17 -0
- data/lib/ppe_api/country.rb +3 -1
- data/lib/ppe_api/designation.rb +3 -1
- data/lib/ppe_api/iucn_category.rb +3 -2
- data/lib/ppe_api/jurisdiction.rb +1 -0
- data/lib/ppe_api/language.rb +1 -0
- data/lib/ppe_api/legal_status.rb +2 -1
- data/lib/ppe_api/point_geom.rb +1 -0
- data/lib/ppe_api/polygon_geom.rb +1 -0
- data/lib/ppe_api/protected_area.rb +2 -1
- data/lib/ppe_api/region.rb +1 -0
- data/lib/ppe_api/site.rb +3 -1
- data/lib/ppe_api/user.rb +1 -18
- data/lib/ppe_api.rb +1 -0
- metadata +15 -16
- data/test/factories.rb +0 -106
- data/test/test_helper.rb +0 -62
@@ -0,0 +1,17 @@
|
|
1
|
+
module PPE_API
|
2
|
+
|
3
|
+
module Config
|
4
|
+
require 'net/http'
|
5
|
+
@@ppe_domain = "localhost"
|
6
|
+
@@ppe_port = 3000
|
7
|
+
@@ppe_path = "/api"
|
8
|
+
@@http = Net::HTTP.new(@@ppe_domain, @@ppe_port)
|
9
|
+
|
10
|
+
#ALLOW ACCESS FROM THE OUTSIDE WORLD
|
11
|
+
class_variables.each do |v|
|
12
|
+
mattr_accessor v[(2..-1)]
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/lib/ppe_api/country.rb
CHANGED
@@ -2,6 +2,7 @@ module PPE_API
|
|
2
2
|
class Country
|
3
3
|
include ::HappyMapper
|
4
4
|
|
5
|
+
tag "country"
|
5
6
|
element :id, Integer
|
6
7
|
element :created_at, DateTime, :tag=>'created-at'
|
7
8
|
element :updated_at, DateTime, :tag=>'updated-at'
|
@@ -17,7 +18,8 @@ module PPE_API
|
|
17
18
|
end
|
18
19
|
|
19
20
|
def self.get_by_iso(iso)
|
20
|
-
res, data =
|
21
|
+
res, data = Config.http.get("/api/country/iso/#{iso}")
|
22
|
+
res.value
|
21
23
|
Country.parse(data) unless data.nil? || data.empty?
|
22
24
|
end
|
23
25
|
|
data/lib/ppe_api/designation.rb
CHANGED
@@ -2,6 +2,7 @@ module PPE_API
|
|
2
2
|
class Designation
|
3
3
|
include ::HappyMapper
|
4
4
|
|
5
|
+
tag "designation"
|
5
6
|
element :id, Integer
|
6
7
|
element :created_at, DateTime, :tag=>'created-at'
|
7
8
|
element :name, String
|
@@ -9,7 +10,8 @@ module PPE_API
|
|
9
10
|
has_one :jurisdiction, Jurisdiction
|
10
11
|
|
11
12
|
def self.get_by_name(name)
|
12
|
-
res, data =
|
13
|
+
res, data = Config.http.post("/api/designation/name", "name=#{name}")
|
14
|
+
res.value
|
13
15
|
return Designation.parse(data) unless data.nil? || data.empty?
|
14
16
|
return nil
|
15
17
|
|
@@ -10,8 +10,9 @@ module PPE_API
|
|
10
10
|
element :value, Integer
|
11
11
|
|
12
12
|
def self.get_by_name(name)
|
13
|
-
res, data =
|
14
|
-
|
13
|
+
res, data = Config.http.get("/api/iucn_category/name/#{name}")
|
14
|
+
res.value
|
15
|
+
return self.parse(data) unless data.nil? || data.empty?
|
15
16
|
return nil
|
16
17
|
|
17
18
|
end
|
data/lib/ppe_api/jurisdiction.rb
CHANGED
data/lib/ppe_api/language.rb
CHANGED
data/lib/ppe_api/legal_status.rb
CHANGED
@@ -10,7 +10,8 @@ module PPE_API
|
|
10
10
|
|
11
11
|
def self.get_by_name(name)
|
12
12
|
unless name.nil? || name.empty?
|
13
|
-
res, data =
|
13
|
+
res, data = Config.http.post("/api/legal_status/name", "name=#{name}")
|
14
|
+
res.value
|
14
15
|
return LegalStatus.parse(data) unless data.nil? || data.empty?
|
15
16
|
end
|
16
17
|
return nil
|
data/lib/ppe_api/point_geom.rb
CHANGED
data/lib/ppe_api/polygon_geom.rb
CHANGED
@@ -90,7 +90,8 @@ module PPE_API
|
|
90
90
|
if id.to_i != 0
|
91
91
|
path = "/api/protected_area/#{id}"
|
92
92
|
path = path + "?has_geometry=true" if has_geom
|
93
|
-
res, data =
|
93
|
+
res, data = Config.http.get(path)
|
94
|
+
res.value
|
94
95
|
return ProtectedArea.parse(data) unless data.nil? || data.empty?
|
95
96
|
end
|
96
97
|
return nil
|
data/lib/ppe_api/region.rb
CHANGED
data/lib/ppe_api/site.rb
CHANGED
@@ -2,6 +2,7 @@ module PPE_API
|
|
2
2
|
class Site
|
3
3
|
include ::HappyMapper
|
4
4
|
|
5
|
+
tag "site"
|
5
6
|
element :id, Integer
|
6
7
|
element :created_at, DateTime, :tag=>'created-at'
|
7
8
|
element :updated_at, DateTime, :tag=>'updated-at'
|
@@ -9,7 +10,8 @@ module PPE_API
|
|
9
10
|
element :state, String
|
10
11
|
|
11
12
|
def self.get_by_id(id)
|
12
|
-
res, data =
|
13
|
+
res, data = Config.http.get("/api/site/#{id}")
|
14
|
+
res.value
|
13
15
|
return Site.parse(data) unless data.nil? || data.empty?
|
14
16
|
return nil
|
15
17
|
end
|
data/lib/ppe_api/user.rb
CHANGED
@@ -2,6 +2,7 @@ module PPE_API
|
|
2
2
|
class User
|
3
3
|
include ::HappyMapper
|
4
4
|
|
5
|
+
tag "user"
|
5
6
|
element :id, Integer
|
6
7
|
element :created_at, DateTime, :tag=>'created-at'
|
7
8
|
element :updated_at, DateTime, :tag=>'updated-at'
|
@@ -13,24 +14,6 @@ module PPE_API
|
|
13
14
|
element :email, String
|
14
15
|
|
15
16
|
|
16
|
-
def exports
|
17
|
-
Export.find_all_by_user_id(id)
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def completed_tasks
|
22
|
-
exports.inject(0) do |sum,ex|
|
23
|
-
if ex.task_status == DR::Config.import_state_map[:completed]
|
24
|
-
sum+=1
|
25
|
-
end
|
26
|
-
sum
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def imports
|
31
|
-
Import.find_all_by_user_id(id)
|
32
|
-
end
|
33
|
-
|
34
17
|
def to_xml(options={})
|
35
18
|
self.as_json.to_xml({:root => "user"}.merge(options))
|
36
19
|
end
|
data/lib/ppe_api.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ppe_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Anonymous PPE Developer
|
8
8
|
autorequire: data_rec_gem
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-23 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -31,26 +31,25 @@ extensions: []
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
33
|
files:
|
34
|
-
- lib/ppe_api/
|
35
|
-
- lib/ppe_api/
|
34
|
+
- lib/ppe_api/jurisdiction.rb
|
35
|
+
- lib/ppe_api/region.rb
|
36
36
|
- lib/ppe_api/apa_relation.rb
|
37
|
+
- lib/ppe_api/polygon_geom.rb
|
38
|
+
- lib/ppe_api/language.rb
|
37
39
|
- lib/ppe_api/country.rb
|
38
|
-
- lib/ppe_api/
|
40
|
+
- lib/ppe_api/user.rb
|
39
41
|
- lib/ppe_api/designation.rb
|
40
|
-
- lib/ppe_api/
|
41
|
-
- lib/ppe_api/jurisdiction.rb
|
42
|
-
- lib/ppe_api/language.rb
|
43
|
-
- lib/ppe_api/legal_status.rb
|
42
|
+
- lib/ppe_api/search.rb
|
44
43
|
- lib/ppe_api/point_geom.rb
|
45
|
-
- lib/ppe_api/
|
44
|
+
- lib/ppe_api/iucn_category.rb
|
45
|
+
- lib/ppe_api/constants_application.rb
|
46
46
|
- lib/ppe_api/protected_area.rb
|
47
|
-
- lib/ppe_api/
|
48
|
-
- lib/ppe_api/
|
47
|
+
- lib/ppe_api/dataset.rb
|
48
|
+
- lib/ppe_api/abstract_pa.rb
|
49
|
+
- lib/ppe_api/alternative_name.rb
|
50
|
+
- lib/ppe_api/legal_status.rb
|
49
51
|
- lib/ppe_api/site.rb
|
50
|
-
- lib/ppe_api/user.rb
|
51
52
|
- lib/ppe_api.rb
|
52
|
-
- test/factories.rb
|
53
|
-
- test/test_helper.rb
|
54
53
|
has_rdoc: true
|
55
54
|
homepage:
|
56
55
|
licenses: []
|
data/test/factories.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
Factory.define :abstract_pa, :default_strategy => :build do |t|
|
2
|
-
end
|
3
|
-
|
4
|
-
Factory.define :designation, :default_strategy => :build do |t|
|
5
|
-
t.name "World Heritage Site"
|
6
|
-
end
|
7
|
-
|
8
|
-
Factory.define :iucn_category, :default_strategy => :build do |t|
|
9
|
-
t.name "Ia"
|
10
|
-
t.value 1
|
11
|
-
end
|
12
|
-
|
13
|
-
Factory.define :legal_status, :default_strategy => :build do |t|
|
14
|
-
t.name "created"
|
15
|
-
end
|
16
|
-
|
17
|
-
Factory.define :country, :default_strategy => :build do |t|
|
18
|
-
t.name "United Kingdom"
|
19
|
-
t.iso "GB"
|
20
|
-
t.iso_3 "GBR"
|
21
|
-
t.association :region
|
22
|
-
end
|
23
|
-
|
24
|
-
Factory.define :region, :default_strategy => :build do |t|
|
25
|
-
t.name "Europe"
|
26
|
-
t.code "EU"
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
Factory.define :polygon_geom, :default_strategy => :build do |t|
|
33
|
-
t.the_geom MultiPolygon.from_polygons([Polygon.from_coordinates([[[12.4,-45.3],[45.4,41.6],[4.456,1.0698],[12.4,-45.3]],[[2.4,5.3],[5.4,1.4263],[14.46,1.06],[2.4,5.3]]]),Polygon.from_coordinates([[[0,0],[4,0],[4,4],[0,4],[0,0]],[[1,1],[3,1],[3,3],[1,3],[1,1]]])], 4326)
|
34
|
-
end
|
35
|
-
|
36
|
-
Factory.define :point_geom, :default_strategy => :build do |t|
|
37
|
-
t.the_geom Point.from_coordinates([1,2], 4326)
|
38
|
-
end
|
39
|
-
|
40
|
-
Factory.define :dataset, :default_strategy => :build do |t|
|
41
|
-
t.citation "Some dataset name"
|
42
|
-
t.author "Galt, J. & Timmy, L."
|
43
|
-
t.association :user
|
44
|
-
end
|
45
|
-
|
46
|
-
Factory.define :user, :default_strategy => :build do |t|
|
47
|
-
t.title "Mr"
|
48
|
-
t.first_name "simon"
|
49
|
-
t.last_name "tokumine"
|
50
|
-
t.sequence(:username) {|n| "simon#{n}"}
|
51
|
-
t.sequence(:email) {|n| "simon#{n}@tokumine.com"}
|
52
|
-
t.password "secret"
|
53
|
-
t.password_confirmation "secret"
|
54
|
-
t.first_login_ip "88.96.173.198"
|
55
|
-
t.latitude 53.6167
|
56
|
-
t.longitude -2.15
|
57
|
-
t.association :country
|
58
|
-
end
|
59
|
-
|
60
|
-
Factory.define :species, :default_strategy => :build do |t|
|
61
|
-
t.name "elephant"
|
62
|
-
t.url "http://somwere.com"
|
63
|
-
t.association :site
|
64
|
-
end
|
65
|
-
|
66
|
-
Factory.define :point_of_interest, :default_strategy => :build do |t|
|
67
|
-
t.title "waterfall"
|
68
|
-
t.summary "nice waterfall"
|
69
|
-
t.url "http://www.google.com"
|
70
|
-
end
|
71
|
-
|
72
|
-
Factory.define :image, :default_strategy => :build do |u|
|
73
|
-
u.photo { ActionController::TestUploadedFile.new(File.join(RAILS_ROOT, 'test', 'resources', 'chewie.jpg')) }
|
74
|
-
end
|
75
|
-
|
76
|
-
Factory.define :image_han, :class => :image, :default_strategy => :build do |u|
|
77
|
-
u.photo { ActionController::TestUploadedFile.new(File.join(RAILS_ROOT, 'test', 'resources', 'han.jpg')) }
|
78
|
-
end
|
79
|
-
|
80
|
-
Factory.define :site, :default_strategy => :build do |t|
|
81
|
-
t.association :abstract_pa
|
82
|
-
end
|
83
|
-
|
84
|
-
Factory.define :protected_area, :default_strategy => :build do |t|
|
85
|
-
t.state "complete"
|
86
|
-
t.english_name "Yosemite"
|
87
|
-
t.local_name "Yosemite"
|
88
|
-
t.total_area 123123
|
89
|
-
t.total_area_marine 32432
|
90
|
-
t.status_date 10.years.ago
|
91
|
-
t.legally_extended true
|
92
|
-
t.legally_reduced false
|
93
|
-
t.legally_reclassified false
|
94
|
-
t.association :site
|
95
|
-
t.association :designation
|
96
|
-
t.association :iucn_category
|
97
|
-
t.association :legal_status
|
98
|
-
t.association :polygon_geom
|
99
|
-
t.association :point_geom
|
100
|
-
t.association :dataset
|
101
|
-
t.association :user
|
102
|
-
end
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
data/test/test_helper.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
ENV["RAILS_ENV"] = "test"
|
2
|
-
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
3
|
-
require 'test_help'
|
4
|
-
|
5
|
-
class ActiveSupport::TestCase
|
6
|
-
# Transactional fixtures accelerate your tests by wrapping each test method
|
7
|
-
# in a transaction that's rolled back on completion. This ensures that the
|
8
|
-
# test database remains unchanged so your fixtures don't have to be reloaded
|
9
|
-
# between every test method. Fewer database queries means faster tests.
|
10
|
-
#
|
11
|
-
# Read Mike Clark's excellent walkthrough at
|
12
|
-
# http://clarkware.com/cgi/blosxom/2005/10/24#Rails10FastTesting
|
13
|
-
#
|
14
|
-
# Every Active Record database supports transactions except MyISAM tables
|
15
|
-
# in MySQL. Turn off transactional fixtures in this case; however, if you
|
16
|
-
# don't care one way or the other, switching from MyISAM to InnoDB tables
|
17
|
-
# is recommended.
|
18
|
-
#
|
19
|
-
# The only drawback to using transactional fixtures is when you actually
|
20
|
-
# need to test transactions. Since your test is bracketed by a transaction,
|
21
|
-
# any transactions started in your code will be automatically rolled back.
|
22
|
-
self.use_transactional_fixtures = true
|
23
|
-
|
24
|
-
# Instantiated fixtures are slow, but give you @david where otherwise you
|
25
|
-
# would need people(:david). If you don't want to migrate your existing
|
26
|
-
# test cases which use the @david style and don't mind the speed hit (each
|
27
|
-
# instantiated fixtures translates to a database query per test method),
|
28
|
-
# then set this back to true.
|
29
|
-
self.use_instantiated_fixtures = false
|
30
|
-
|
31
|
-
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
|
32
|
-
#
|
33
|
-
# Note: You'll currently still have to declare fixtures explicitly in integration tests
|
34
|
-
# -- they do not yet inherit this setting
|
35
|
-
fixtures :all
|
36
|
-
|
37
|
-
# Add more helper methods to be used by all tests here...
|
38
|
-
end
|
39
|
-
|
40
|
-
class PGconn
|
41
|
-
def PGconn.quote_ident(name)
|
42
|
-
%("#{name}")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Test::Unit::TestCase
|
47
|
-
def self.should_have_attached_file(attachment)
|
48
|
-
klass = self.name.gsub(/Test$/, '').constantize
|
49
|
-
|
50
|
-
context "To support a paperclip attachment named #{attachment}, #{klass}" do
|
51
|
-
should_have_db_column("#{attachment}_file_name", :type => :string)
|
52
|
-
should_have_db_column("#{attachment}_content_type", :type => :string)
|
53
|
-
should_have_db_column("#{attachment}_file_size", :type => :integer)
|
54
|
-
end
|
55
|
-
|
56
|
-
should "have a paperclip attachment named ##{attachment}" do
|
57
|
-
assert klass.new.respond_to?(attachment.to_sym),
|
58
|
-
"@#{klass.name.underscore} doesn't have a paperclip field named #{attachment}"
|
59
|
-
assert_equal Paperclip::Attachment, klass.new.send(attachment.to_sym).class
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|