localwiki_client 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/History.txt +5 -0
  4. data/README.md +17 -9
  5. data/Rakefile +6 -0
  6. data/integration/helper.rb +1 -1
  7. data/integration/live_saltlake_wiki_spec.rb +2 -2
  8. data/integration/live_test_wiki_spec.rb +26 -11
  9. data/lib/localwiki/client.rb +143 -115
  10. data/lib/localwiki/resource.rb +76 -0
  11. data/lib/localwiki/version.rb +1 -1
  12. data/lib/localwiki_client.rb +1 -0
  13. data/localwiki_client.gemspec +1 -0
  14. data/spec/basic_crud_spec.rb +12 -5
  15. data/spec/basic_spec.rb +2 -2
  16. data/spec/fixtures/cassettes/basic.yml +21 -19
  17. data/spec/fixtures/cassettes/basic_crud.yml +21 -19
  18. data/spec/fixtures/cassettes/basic_crud_delete_fail.yml +11 -9
  19. data/spec/fixtures/cassettes/basic_crud_delete_success.yml +10 -8
  20. data/spec/fixtures/cassettes/basic_crud_page_by_name_success.yml +40 -0
  21. data/spec/fixtures/cassettes/basic_crud_read_fail.yml +22 -34
  22. data/spec/fixtures/cassettes/basic_crud_read_success.yml +11 -11
  23. data/spec/fixtures/cassettes/basic_crud_update_success.yml +11 -9
  24. data/spec/fixtures/cassettes/basic_fetch_version_success.yml +41 -37
  25. data/spec/fixtures/cassettes/basic_page_by_name_spaces.yml +12 -12
  26. data/spec/fixtures/cassettes/basic_unique_authors_success.yml +41 -37
  27. data/spec/fixtures/cassettes/fetch.yml +8 -8
  28. data/spec/fixtures/cassettes/list.yml +93 -0
  29. data/spec/fixtures/cassettes/list_file_success.yml +40 -0
  30. data/spec/fixtures/cassettes/list_limit_success.yml +124 -0
  31. data/spec/fixtures/cassettes/list_map_success.yml +42 -0
  32. data/spec/fixtures/cassettes/list_page_success.yml +1108 -0
  33. data/spec/fixtures/cassettes/list_page_tags_success.yml +42 -0
  34. data/spec/fixtures/cassettes/list_site_success.yml +46 -0
  35. data/spec/fixtures/cassettes/list_tag_success.yml +43 -0
  36. data/spec/fixtures/cassettes/list_user_success.yml +56 -0
  37. data/spec/fixtures/cassettes/localwiki_client.yml +121 -115
  38. data/spec/fixtures/cassettes/slug.yml +8 -8
  39. data/spec/helper.rb +7 -0
  40. data/spec/list_spec.rb +47 -0
  41. data/spec/localwiki_client_spec.rb +4 -12
  42. data/spec/localwiki_spec.rb +17 -0
  43. data/spec/map_spec.rb +135 -0
  44. data/spec/resource_spec.rb +60 -0
  45. metadata +33 -4
@@ -7,23 +7,23 @@ http_interactions:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
9
  headers:
10
+ User-Agent:
11
+ - Faraday v0.8.7
10
12
  Accept-Encoding:
11
13
  - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
14
  Accept:
13
- - ! '*/*'
14
- User-Agent:
15
- - Ruby
15
+ - '*/*'
16
16
  response:
17
17
  status:
18
18
  code: 200
19
19
  message: OK
20
20
  headers:
21
21
  Date:
22
- - Sat, 16 Mar 2013 01:07:54 GMT
22
+ - Fri, 29 Mar 2013 02:07:25 GMT
23
23
  Server:
24
24
  - Apache/2.2.22 (Ubuntu)
25
25
  Access-Control-Allow-Origin:
26
- - ! '*'
26
+ - '*'
27
27
  Access-Control-Allow-Methods:
28
28
  - POST,GET,OPTIONS,PUT,DELETE
29
29
  Transfer-Encoding:
@@ -31,8 +31,8 @@ http_interactions:
31
31
  Content-Type:
32
32
  - application/vnd.api.v1+json; charset=utf-8
33
33
  body:
34
- encoding: US-ASCII
35
- string: ! '{"domain": "example.com", "id": 1, "language_code": "en-us", "license":
34
+ encoding: UTF-8
35
+ string: '{"domain": "example.com", "id": 1, "language_code": "en-us", "license":
36
36
  "<p>Except where otherwise noted, this content is licensed under a <a rel=\"license\"
37
37
  href=\"http://creativecommons.org/licenses/by/3.0/\">Creative Commons Attribution
38
38
  License</a>. See <a href=\"/Copyrights\">Copyrights.</p>", "name": "example.com",
@@ -42,5 +42,5 @@ http_interactions:
42
42
  See <a href=\"/Copyrights\" target=\"_blank\">Copyrights</a>.", "time_zone":
43
43
  "America/Chicago"}'
44
44
  http_version:
45
- recorded_at: Sat, 16 Mar 2013 01:07:23 GMT
45
+ recorded_at: Fri, 29 Mar 2013 02:06:40 GMT
46
46
  recorded_with: VCR 2.4.0
data/spec/helper.rb CHANGED
@@ -1,3 +1,10 @@
1
+ begin
2
+ require 'simplecov'
3
+ SimpleCov.start if ENV["COVERAGE"]
4
+ rescue Exception => e
5
+ puts 'Run "gem install simplecov" to enable code coverage reporting'
6
+ end
7
+
1
8
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
9
  require 'localwiki_client'
3
10
  require 'webmock/rspec'
data/spec/list_spec.rb ADDED
@@ -0,0 +1,47 @@
1
+ require File.expand_path("../helper", __FILE__)
2
+
3
+ describe 'LocalwikiClient' do
4
+
5
+ before(:all) do
6
+ VCR.insert_cassette 'list', :record => :new_episodes
7
+ @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
8
+ ENV['localwiki_client_user'],
9
+ ENV['localwiki_client_apikey']
10
+ require 'securerandom'
11
+ @pagename = "TestPageForListing#{SecureRandom.uuid}"
12
+ @wiki.create('page', {name: @pagename, content: "<p>Created List Test Page #{@pagename}!</p>"}.to_json)
13
+ end
14
+
15
+ after(:all) do
16
+ VCR.eject_cassette
17
+ end
18
+
19
+ context "#list" do
20
+
21
+ # resource_type => validation_field
22
+ {'site' => 'language_code',
23
+ 'user' => 'first_name',
24
+ 'page' => 'name',
25
+ 'file' => 'file',
26
+ 'map' => 'geom',
27
+ 'tag' => 'slug',
28
+ 'page_tags' => 'tags'}.each do |resource, field|
29
+
30
+ it "#list('#{resource}') returns collection of #{resource} objects" do
31
+ VCR.use_cassette "list_#{resource}_success", :match_requests_on => [:method, :path] do
32
+ @wiki.list(resource).last.should respond_to field.intern
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ it "limit parameter limits number of resources returned" do
39
+ VCR.use_cassette 'list_limit_success', :match_requests_on => [:method, :path] do
40
+ response = @wiki.list('page', 3)
41
+ response.length.should eq 3
42
+ end
43
+ end
44
+
45
+
46
+ end
47
+ end
@@ -13,20 +13,16 @@ describe 'LocalwikiClient' do
13
13
 
14
14
  context 'attributes' do
15
15
 
16
- context '#site_name' do
17
- it { @wiki.site_name.should eq 'example.com' }
16
+ context '#name' do
17
+ it { @wiki.site.name.should eq 'example.com' }
18
18
  end
19
19
 
20
20
  context '#time_zone' do
21
- it { @wiki.time_zone.should eq 'America/Chicago' }
21
+ it { @wiki.site.time_zone.should eq 'America/Chicago' }
22
22
  end
23
23
 
24
24
  context '#language_code' do
25
- it { @wiki.language_code.should eq 'en-us' }
26
- end
27
-
28
- context '#page_by_name' do
29
- it 'returns page body'
25
+ it { @wiki.site.language_code.should eq 'en-us' }
30
26
  end
31
27
 
32
28
  %W{site page user file map tag page_tags}.each do |resource|
@@ -35,9 +31,5 @@ describe 'LocalwikiClient' do
35
31
  end
36
32
  end
37
33
 
38
- context '#list' do
39
- it 'returns list of items matching'
40
- end
41
-
42
34
  end
43
35
  end
@@ -0,0 +1,17 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib/localwiki", __FILE__)
2
+ require 'resource'
3
+
4
+ describe 'Localwiki' do
5
+
6
+ context 'methods' do
7
+
8
+ context '::make_one' do
9
+
10
+ it "creates instance of specified resource from json" do
11
+ page = Localwiki::make_one(:page, {name: 'a page', id: '34'})
12
+ page.class.should be Localwiki::Page
13
+ end
14
+
15
+ end
16
+ end
17
+ end
data/spec/map_spec.rb ADDED
@@ -0,0 +1,135 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib/localwiki", __FILE__)
2
+ require 'resource'
3
+ require 'json'
4
+
5
+ describe 'Localwiki' do
6
+
7
+ context '::Map' do
8
+
9
+ context 'instance with single points coordinates' do
10
+
11
+ before(:all) do
12
+ json = %@{
13
+ "geom":
14
+ {"geometries":
15
+ [{"coordinates":
16
+ [-122.370919, 47.570641], "type": "Point"}
17
+ ],
18
+ "type": "GeometryCollection"
19
+ },
20
+ "id": 390,
21
+ "length": 0.0,
22
+ "lines": null,
23
+ "page": "/api/page/Luna_Park_Cafe",
24
+ "points": {"coordinates": [[-122.370919, 47.570641]], "type": "MultiPoint"},
25
+ "polys": null,
26
+ "resource_uri": "/api/map/Luna_Park_Cafe"
27
+ }@
28
+ @map = Localwiki::Map.new(JSON.parse(json))
29
+ end
30
+
31
+ it "#single_point? is true where points contains only one point" do
32
+ @map.should be_single_point
33
+ end
34
+
35
+ it "#line? is not true where lines attribute is not null" do
36
+ @map.should_not be_line
37
+ end
38
+
39
+ it "#poly? is not true where polys attribute is not null" do
40
+ @map.should_not be_poly
41
+ end
42
+
43
+ it "#lat contains lattitude if #single_point?" do
44
+ @map.lat.should eq -122.370919
45
+ end
46
+
47
+ it "#long contains longitude if #single_point?" do
48
+ @map.long.should eq 47.570641
49
+ end
50
+
51
+ end
52
+
53
+ context 'instance with multiple points coordinates' do
54
+
55
+ before(:all) do
56
+ json = %@{
57
+ "geom": {
58
+ "geometries": [
59
+ {"coordinates": [-122.315414, 47.664818], "type": "Point"},
60
+ {"coordinates": [-122.380344, 47.561239], "type": "Point"}
61
+ ],
62
+ "type": "GeometryCollection"
63
+ },
64
+ "id": 5,
65
+ "length": 0.0,
66
+ "lines": null,
67
+ "page": "/api/page/Chaco_Canyon_Cafe",
68
+ "points": {
69
+ "coordinates": [
70
+ [-122.315414, 47.664818],
71
+ [-122.380344, 47.561239]
72
+ ],
73
+ "type": "MultiPoint"
74
+ },
75
+ "polys": null,
76
+ "resource_uri": "/api/map/Chaco_Canyon_Cafe"
77
+ }@
78
+ @map = Localwiki::Map.new(JSON.parse(json))
79
+ end
80
+
81
+ it "#single_point? is false where points contains more than one point" do
82
+ @map.should_not be_single_point
83
+ end
84
+
85
+ it "#lat is nil where multiple points coordinates exist" do
86
+ @map.lat.should be_nil
87
+ end
88
+
89
+ it "#long is nil where multiple points coordinates exist" do
90
+ @map.long.should be_nil
91
+ end
92
+
93
+ end
94
+
95
+ context 'instance with polys coordinates' do
96
+
97
+ before(:all) do
98
+ json = %@{
99
+ "geom":
100
+ {"geometries":
101
+ [{"coordinates":
102
+ [[
103
+ [-122.38683, 47.596621], [-122.400563, 47.585159], [-122.419789, 47.575548], [-122.400906, 47.554468], [-122.397473, 47.53755], [-122.40022, 47.529437], [-122.39507, 47.524801], [-122.399361, 47.51715], [-122.321599, 47.516918], [-122.320569, 47.531871], [-122.329838, 47.537087], [-122.345288, 47.55748], [-122.348721, 47.566978], [-122.357991, 47.573348], [-122.363141, 47.584175], [-122.371209, 47.583567], [-122.38683, 47.596621]]], "type": "Polygon"}], "type": "GeometryCollection"}, "id": 389, "length": 0.299969686560957, "lines": null, "page": "/api/page/West_Seattle", "points": null, "polys": {"coordinates": [[[[-122.38683, 47.596621], [-122.400563, 47.585159], [-122.419789, 47.575548], [-122.400906, 47.554468], [-122.397473, 47.53755], [-122.40022, 47.529437], [-122.39507, 47.524801], [-122.399361, 47.51715], [-122.321599, 47.516918], [-122.320569, 47.531871], [-122.329838, 47.537087], [-122.345288, 47.55748], [-122.348721, 47.566978], [-122.357991, 47.573348], [-122.363141, 47.584175], [-122.371209, 47.583567], [-122.38683, 47.596621]
104
+ ]]
105
+ ],
106
+ "type": "MultiPolygon"
107
+ },
108
+ "resource_uri": "/api/map/West_Seattle"
109
+ }@
110
+ @map = Localwiki::Map.new(JSON.parse(json))
111
+ end
112
+
113
+ it "#single_point? is not true where points attribute is null" do
114
+ @map.should_not be_single_point
115
+ end
116
+
117
+ it "#lat is nil where no points coordinates exist" do
118
+ @map.lat.should be_nil
119
+ end
120
+
121
+ it "#long is nil where no points coordinates exist" do
122
+ @map.long.should be_nil
123
+ end
124
+
125
+ it "#line? is not true where lines attribute is null" do
126
+ @map.should_not be_line
127
+ end
128
+
129
+ it "#poly? is true where polys attribute is not null" do
130
+ @map.should be_poly
131
+ end
132
+
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,60 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib/localwiki", __FILE__)
2
+ require 'resource'
3
+ require 'json'
4
+
5
+ describe 'Localwiki' do
6
+
7
+ context 'Resource' do
8
+
9
+ context "instance" do
10
+
11
+ it "accepts and stores json" do
12
+ resource = Localwiki::Resource.new({my_key: 'my_value'})
13
+ resource.json.should eq({:my_key => "my_value"})
14
+ end
15
+
16
+ it "responds with values when sent messages that match keys" do
17
+ resource = Localwiki::Resource.new({my_key: 'my_value'})
18
+ resource.my_key.should eq 'my_value'
19
+ end
20
+
21
+ it "responds with nil when sent messages that don't match keys" do
22
+ resource = Localwiki::Resource.new({my_key: 'my_value'})
23
+ resource.my_key.should eq 'my_value'
24
+ end
25
+
26
+ end
27
+ end
28
+
29
+ context '::Page' do
30
+
31
+ context "instance" do
32
+
33
+ before(:all) do
34
+ json = %@{
35
+ "content": "<p>Bradfordville Blues Club experience is like no other. It combines a truly unique location and atmosphere with the best the Blues has to offer. </p>",
36
+ "id": 158,
37
+ "map": "/api/map/Bradfordville_Blues_Club",
38
+ "name": "Bradfordville Blues Club",
39
+ "page_tags": "/api/page_tags/Bradfordville_Blues_Club",
40
+ "resource_uri": "/api/page/Bradfordville_Blues_Club",
41
+ "slug": "bradfordville blues club"
42
+ }@
43
+ @page = Localwiki::Page.new(JSON.parse(json))
44
+ end
45
+
46
+ it "#id is correct" do
47
+ @page.id.should eq 158
48
+ end
49
+
50
+ it "#resource_uri is correct" do
51
+ @page.resource_uri.should eq "/api/page/Bradfordville_Blues_Club"
52
+ end
53
+
54
+ it "#slug is correct" do
55
+ @page.slug.should eq "bradfordville blues club"
56
+ end
57
+
58
+ end
59
+ end
60
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: localwiki_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Faloona
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-16 00:00:00.000000000 Z
12
+ date: 2013-03-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -129,6 +129,20 @@ dependencies:
129
129
  - - '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
+ - !ruby/object:Gem::Dependency
133
+ name: simplecov
134
+ requirement: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ type: :development
140
+ prerelease: false
141
+ version_requirements: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
132
146
  - !ruby/object:Gem::Dependency
133
147
  name: rb-fsevent
134
148
  requirement: !ruby/object:Gem::Requirement
@@ -203,6 +217,7 @@ files:
203
217
  - integration/live_saltlake_wiki_spec.rb
204
218
  - integration/live_test_wiki_spec.rb
205
219
  - lib/localwiki/client.rb
220
+ - lib/localwiki/resource.rb
206
221
  - lib/localwiki/version.rb
207
222
  - lib/localwiki_client.rb
208
223
  - localwiki_client.gemspec
@@ -213,6 +228,7 @@ files:
213
228
  - spec/fixtures/cassettes/basic_crud.yml
214
229
  - spec/fixtures/cassettes/basic_crud_delete_fail.yml
215
230
  - spec/fixtures/cassettes/basic_crud_delete_success.yml
231
+ - spec/fixtures/cassettes/basic_crud_page_by_name_success.yml
216
232
  - spec/fixtures/cassettes/basic_crud_read_fail.yml
217
233
  - spec/fixtures/cassettes/basic_crud_read_success.yml
218
234
  - spec/fixtures/cassettes/basic_crud_update_success.yml
@@ -220,16 +236,29 @@ files:
220
236
  - spec/fixtures/cassettes/basic_page_by_name_spaces.yml
221
237
  - spec/fixtures/cassettes/basic_unique_authors_success.yml
222
238
  - spec/fixtures/cassettes/fetch.yml
239
+ - spec/fixtures/cassettes/list.yml
240
+ - spec/fixtures/cassettes/list_file_success.yml
241
+ - spec/fixtures/cassettes/list_limit_success.yml
242
+ - spec/fixtures/cassettes/list_map_success.yml
243
+ - spec/fixtures/cassettes/list_page_success.yml
244
+ - spec/fixtures/cassettes/list_page_tags_success.yml
245
+ - spec/fixtures/cassettes/list_site_success.yml
246
+ - spec/fixtures/cassettes/list_tag_success.yml
247
+ - spec/fixtures/cassettes/list_user_success.yml
223
248
  - spec/fixtures/cassettes/localwiki_client.yml
224
249
  - spec/fixtures/cassettes/slug.yml
225
250
  - spec/helper.rb
251
+ - spec/list_spec.rb
226
252
  - spec/localwiki_client_spec.rb
253
+ - spec/localwiki_spec.rb
254
+ - spec/map_spec.rb
255
+ - spec/resource_spec.rb
227
256
  - spec/slug_spec.rb
228
257
  homepage: http://github.com/bfaloona/localwiki_client
229
258
  licenses:
230
259
  - MIT
231
260
  metadata: {}
232
- post_install_message: "\n Thank you for installing localwiki_client 0.2.0\n "
261
+ post_install_message: "\n Thank you for installing localwiki_client 0.3.0\n "
233
262
  rdoc_options:
234
263
  - --charset=UTF-8
235
264
  require_paths:
@@ -249,6 +278,6 @@ rubyforge_project:
249
278
  rubygems_version: 2.0.0
250
279
  signing_key:
251
280
  specification_version: 4
252
- summary: localwiki_client-0.2.0
281
+ summary: localwiki_client-0.3.0
253
282
  test_files: []
254
283
  has_rdoc: