localwiki_client 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb9cc507732637d939aa2fdea6e73523e17b0765
4
- data.tar.gz: c2eaa613db6c5df7cb2dad1940d693fa0a16907b
3
+ metadata.gz: e86f427d07f0b2f5fdb68ce988290fdca41d3e79
4
+ data.tar.gz: 1457723a76e10dc292dc4aaeb453e2ac101c7e78
5
5
  SHA512:
6
- metadata.gz: a62093cafaa6429868d66ff1c4a15187f37c9e93b8fec8666bc9d36602884feba589b18a201aca253aee61e57b193e3d72c61b023ac4acd3dfdd7113cb94fc60
7
- data.tar.gz: 6368549d3fa07caf1678080786626cbcd14442c1864ed176774ce6ef80665a7b6190f0f15b467b8da57dabbd13db055da09b9d62cea6c82f3d0e083c840dbe9a
6
+ metadata.gz: f8bd7d85ae999853e62e2de954b71f2c6efbf076546ccd6ed3efd9f3304fa87f26ed45978c71fa20368e8e9591da2c35698939097f9b8749cb65948b8293eb8c
7
+ data.tar.gz: 65c4b102cc369045bfcf431b1c45a5116eb685fce1b0e9c91b6738bd4ecd8dbc37f568866c94fe512f25474fa09d48ec68796f587cd494a39f0e721eb526432a
@@ -4,3 +4,5 @@ rvm:
4
4
  - 2.0.0
5
5
  - jruby-19mode # JRuby in 1.9 mode
6
6
  - rbx-19mode
7
+ env:
8
+ - localwiki_client_server=ec2-54-234-151-52.compute-1.amazonaws.com
@@ -1,3 +1,8 @@
1
+ === 0.3.1 / 2013-04-02
2
+
3
+ * Follow redirects
4
+ * Added example scripts
5
+
1
6
  === 0.3.0 / 2013-03-28
2
7
 
3
8
  * Localwiki::Resource subclasses used to represent resources
data/README.md CHANGED
@@ -43,6 +43,8 @@ Usage
43
43
  response.status
44
44
  => 201
45
45
 
46
+ More examples scripts can be found in the [examples folder](https://github.com/codeforseattle/localwiki_client/tree/master/examples).
47
+
46
48
  Features / Problems
47
49
  -------------------
48
50
 
@@ -63,21 +65,17 @@ Compatibility
63
65
  Contributing
64
66
  ------------
65
67
 
66
- To get your improvements included, please fork and submit a pull request.
67
-
68
- Bugs and/or failing tests are very appreciated.
68
+ * To get your improvements included, please fork and submit a pull request.
69
+ * Bugs and/or failing tests are very appreciated.
70
+ * See [Contributing to localwiki_client gem](https://github.com/codeforseattle/localwiki_client/wiki/Contributing-to-localwiki_client-gem) for additional details.
69
71
 
70
72
  Contributors
71
73
  ------------
72
- Seth Vincent
73
-
74
- Brandon Faloona
75
-
76
- Helen Canzler
77
-
78
- Jerry Frost
79
-
80
- Matt Adkins
74
+ * Seth Vincent
75
+ * Brandon Faloona
76
+ * Helen Canzler
77
+ * Jerry Frost
78
+ * Matt Adkins
81
79
 
82
80
  LICENSE
83
81
  -------
@@ -0,0 +1,102 @@
1
+ require 'localwiki_client'
2
+
3
+ ##
4
+ # Written by Seth Vincent, Brandon Faloona
5
+ #
6
+ # LocalWiki API doc:
7
+ # localwiki.readthedocs.org/en/latest/api.html
8
+
9
+ localwikis = [
10
+ 'wikislo.org',
11
+ 'miamiwiki.org',
12
+ 'oaklandwiki.org',
13
+ 'saltlakewiki.org',
14
+ 'seattlewiki.net',
15
+ 'cuwiki.net',
16
+ 'conway.localwiki.org',
17
+ 'viget.org',
18
+ 'olywiki.org',
19
+ 'www.bmorepipeline.org',
20
+ 'wikikc.com',
21
+ 'toledowiki.net',
22
+ 'arborwiki.org',
23
+ 'oshima-gdm.jp',
24
+ 'dentonwiki.org',
25
+ 'trianglewiki.org',
26
+ 'scruzwiki.org',
27
+ 'boise.localwiki.org',
28
+ 'antarctica.localwiki.org',
29
+ 'sacwiki.org',
30
+ 'denver-wiki.org',
31
+ 'tacoma.localwiki.org',
32
+ 'denver-wiki.org',
33
+ 'taswiki.net',
34
+ 'barkerwiki.org.au',
35
+ 'sydney.localwiki.org',
36
+ 'southshorewiki.ca',
37
+ 'toronto.localwiki.org',
38
+ 'sfwiki.org',
39
+ 'www.sdwiki.org',
40
+ 'www.wikiofgoodliving.org',
41
+ 'chicowiki.org',
42
+ 'foothills.localwiki.org',
43
+ 'www.newbritainwiki.org',
44
+ 'www.gainesvillewiki.org',
45
+ 'www.tallahasseewiki.org',
46
+ 'decorahwiki.org',
47
+ 'cantonwiki.org',
48
+ 'detroitwiki.org',
49
+ 'wiki.betteralamance.org',
50
+ 'wikikc.org',
51
+ 'twincitieswiki.org',
52
+ 'porttownsendwiki.org',
53
+ 'austin.localwiki.org',
54
+ 'www.mac-wiki.org',
55
+ 'tulsawiki.org',
56
+ 'districtcommons.org',
57
+ 'www.utkalen.se',
58
+ 'www.nquarter.co.uk',
59
+ 'hyderabadwiki.com',
60
+ 'sissachwiki.ch',
61
+ 'www.kingslynnwiki.co.uk',
62
+ 'bermudawiki.org'
63
+ ]
64
+
65
+ def get_wiki_stats(base_url)
66
+
67
+ wiki = LocalwikiClient.new base_url
68
+ site_thread = Thread.current
69
+ site_thread[:output] = []
70
+
71
+ wiki_name = wiki.site.name << "\n"
72
+
73
+ resource_types = ['page', 'user', 'file', 'map']
74
+ resource_types.collect do |resource|
75
+ label = " #{resource.to_s}s: "
76
+ site_thread[:output].push "#{label[0..7]} #{wiki.count(resource).to_s.rjust(6)}"
77
+ end
78
+
79
+ site_thread[:output].sort!.reverse!
80
+ puts wiki_name << site_thread[:output].join("\n")
81
+
82
+ end
83
+
84
+ # for each localwiki, create a thread to collect and print stats
85
+ site_threads = localwikis.collect do |wiki|
86
+
87
+ Thread.new do
88
+ begin
89
+
90
+ sleep 0.05
91
+ get_wiki_stats(wiki)
92
+
93
+ rescue Errno::ETIMEDOUT => timeout
94
+ puts "#{wiki} timed out."
95
+ rescue => e
96
+ puts "#{wiki} returned the error: #{e.message}"
97
+ end
98
+ end
99
+ end
100
+
101
+ puts "Collecting stats on #{site_threads.count} wikis ..."
102
+ site_threads.collect &:join
@@ -0,0 +1,48 @@
1
+ require 'localwiki_client'
2
+ require 'geocoder'
3
+ require 'uri'
4
+
5
+ def print_help
6
+ puts 'Return list of wiki pages (that have location information) near a street address.'
7
+ puts "Parameters:"
8
+ puts "\thostname: localwiki server, e.g.: seattlewiki.net"
9
+ puts "\taddress: street address, e.g.: 350 Monroe Avenue NE, Renton WA"
10
+ puts "\tmiles: number of miles to search (defaults to 1)"
11
+ puts "Usage:\n\tnearby_wiki_pages <hostname> <street address> <miles>"
12
+ exit
13
+ end
14
+
15
+ def uri_to_name uri
16
+ URI.decode(uri.match(/\/([^\/]+)$/)[1]).gsub('_', ' ')
17
+ end
18
+
19
+ print_help if ARGV.length < 2
20
+
21
+ hostname, address, miles = ARGV
22
+
23
+ coordinates = Geocoder.coordinates address
24
+ puts "Finding wiki pages within #{miles} miles of #{coordinates.inspect}"
25
+
26
+ wiki = LocalwikiClient.new hostname
27
+ maps = wiki.list :map
28
+ #puts maps.inspect
29
+
30
+ pages = maps.collect do |map|
31
+ next unless map.single_point?
32
+ actual_distance = Geocoder::Calculations.distance_between([map.lat, map.long], coordinates.reverse)
33
+ #puts actual_distance.to_s + ' :: ' + map.page
34
+ if actual_distance < miles.to_f
35
+ #print '.'
36
+ {:dist => actual_distance, :map => map}
37
+ end
38
+ end
39
+
40
+ pages.compact!
41
+ if pages.size < 1
42
+ puts 'No results found.'
43
+ else
44
+ puts "\nMiles :: Page"
45
+ pages.sort_by{|i|i[:dist]}.each do |entry|
46
+ puts sprintf("%5.2f", entry[:dist]) + " :: #{uri_to_name(entry[:map].page)}"
47
+ end
48
+ end
@@ -2,8 +2,11 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
2
  require 'localwiki_client'
3
3
 
4
4
  def test_env_vars_set?
5
- return true if ENV['localwiki_client_user'] && ENV['localwiki_client_apikey']
5
+ return true if ENV['localwiki_client_server'] && ENV['localwiki_client_user'] && ENV['localwiki_client_apikey']
6
6
  puts "\nTo run all tests in the integration folder you need to do two things:"
7
- puts "\tContact sethvincent@gmail.com to request a username and apikey on the test server."
8
- puts "\tSet these two environment variables:\n\t\texport localwiki_client_user=USERNAME\n\t\texport localwiki_client_apikey=APIKEY"
7
+ puts "\tContact a test server admin to request the hostname, and a username / apikey for your test server."
8
+ puts "\tSet these three environment variables (working example given):"
9
+ puts "\t\texport localwiki_client_server=ec2-54-234-151-52.compute-1.amazonaws.com"
10
+ puts "\t\texport localwiki_client_user=testuser"
11
+ puts "\t\texport localwiki_client_apikey=1ff0ed07625365b8d5589f17088f43b5ae227793"
9
12
  end
@@ -51,11 +51,11 @@ describe 'LIVE testwiki instance' do
51
51
  end
52
52
 
53
53
  it "returns collection of resources objects" do
54
- @response['objects'].first.keys.length.should be > 1
54
+ @response.first.class.superclass.should eq Localwiki::Resource
55
55
  end
56
56
 
57
57
  it "limit parameter limits number of resources returned" do
58
- @response['objects'].length.should eq 2
58
+ @response.length.should eq 2
59
59
  end
60
60
 
61
61
  end
@@ -1,4 +1,5 @@
1
1
  require 'faraday'
2
+ require 'faraday_middleware'
2
3
  require 'json'
3
4
 
4
5
  module Localwiki
@@ -161,7 +162,7 @@ module Localwiki
161
162
  # @return [Localwiki::Resource, Faraday::Response] resource object, or http response object
162
163
  def hydrate(resource_type,param)
163
164
  # skip if given an http response object
164
- return param if param.respond_to? :status
165
+ return param if param.kind_of? Faraday::Response
165
166
  Localwiki::make_one(resource_type,param)
166
167
  end
167
168
 
@@ -172,7 +173,7 @@ module Localwiki
172
173
  # @return [Array, Faraday::Response] array of resource objects, or http response object
173
174
  def hydrate_list(resource_type,param)
174
175
  # skip if given an http response object
175
- return param if param.respond_to? :status
176
+ return param if param.kind_of? Faraday::Response
176
177
  param.collect do |json_hash|
177
178
  Localwiki::make_one(resource_type,json_hash)
178
179
  end
@@ -182,8 +183,13 @@ module Localwiki
182
183
  # initialize Faraday::Connection instance. set @conn and @site
183
184
  # @param [String] hostname localwiki server hostname
184
185
  def initialize_connection(hostname)
185
- @conn = Faraday.new :url => hostname
186
+ @conn = Faraday.new url: hostname do |config|
187
+ config.use FaradayMiddleware::FollowRedirects, limit: 3
188
+ # config.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses
189
+ config.adapter Faraday.default_adapter
190
+ end
186
191
  @site = fetch('site','1')
192
+ raise "Connection failed. #{@site.status} error returned from #{hostname}." if @site.kind_of? Faraday::Response
187
193
  end
188
194
 
189
195
  ##
@@ -204,10 +210,8 @@ module Localwiki
204
210
  # @return [Faraday::Response] http response object
205
211
  def http_post(path, json)
206
212
  @conn.post do |req|
207
- req.url full_url(path)
208
- req.headers['Content-Type'] = 'application/json'
209
- req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
210
- req.body = json
213
+ configure_request req, path, json
214
+ authorize_request req
211
215
  end
212
216
  end
213
217
 
@@ -218,10 +222,8 @@ module Localwiki
218
222
  # @return [Faraday::Response] http response object
219
223
  def http_put(path, json)
220
224
  @conn.put do |req|
221
- req.url full_url(path)
222
- req.headers['Content-Type'] = 'application/json'
223
- req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
224
- req.body = json
225
+ configure_request req, path, json
226
+ authorize_request req
225
227
  end
226
228
  end
227
229
 
@@ -231,9 +233,8 @@ module Localwiki
231
233
  # @return [Faraday::Response] http response object
232
234
  def http_delete(path)
233
235
  @conn.delete do |req|
234
- req.url full_url(path)
235
- req.headers['Content-Type'] = 'application/json'
236
- req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
236
+ configure_request req, path
237
+ authorize_request req
237
238
  end
238
239
  end
239
240
 
@@ -245,5 +246,23 @@ module Localwiki
245
246
  string.to_s.strip.gsub(' ', "_")
246
247
  end
247
248
 
249
+ ##
250
+ # set request parameters
251
+ # @param req Faraday request object
252
+ # @param path request path
253
+ # @param json json string
254
+ def configure_request(req, path, json=nil)
255
+ req.headers['Content-Type'] = 'application/json'
256
+ req.url full_url(path)
257
+ req.body = json
258
+ end
259
+
260
+ ##
261
+ # set request authorization header
262
+ # @param req Faraday request object
263
+ def authorize_request(req)
264
+ req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
265
+ end
266
+
248
267
  end
249
268
  end
@@ -1,5 +1,5 @@
1
1
  module Localwiki
2
2
 
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
 
5
5
  end
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.required_ruby_version = '>= 1.9.2'
15
15
 
16
16
  s.add_dependency('faraday')
17
+ s.add_dependency('faraday_middleware')
17
18
  s.add_dependency('json_pure')
18
19
 
19
20
  s.add_development_dependency('rake')
@@ -4,7 +4,7 @@ describe 'LocalwikiClient' do
4
4
 
5
5
  before(:all) do
6
6
  VCR.insert_cassette 'basic_crud', :record => :new_episodes
7
- @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
7
+ @wiki = Localwiki::Client.new ENV['localwiki_client_server'],
8
8
  ENV['localwiki_client_user'],
9
9
  ENV['localwiki_client_apikey']
10
10
  require 'securerandom'
@@ -6,7 +6,7 @@ describe 'LocalwikiClient' do
6
6
 
7
7
  before(:all) do
8
8
  VCR.insert_cassette 'basic', :record => :new_episodes
9
- @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
9
+ @wiki = Localwiki::Client.new ENV['localwiki_client_server'],
10
10
  ENV['localwiki_client_user'],
11
11
  ENV['localwiki_client_apikey']
12
12
  end
@@ -4,7 +4,7 @@ describe 'LocalwikiClient' do
4
4
 
5
5
  before(:all) do
6
6
  VCR.insert_cassette 'fetch', :record => :new_episodes
7
- @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
7
+ @wiki = Localwiki::Client.new ENV['localwiki_client_server'],
8
8
  ENV['localwiki_client_user'],
9
9
  ENV['localwiki_client_apikey']
10
10
  require 'securerandom'
@@ -16,8 +16,11 @@ VCR.configure do |c|
16
16
  # c.debug_logger = File.open('spec/fixtures/cassettes/debug_vcr.log', 'w')
17
17
  end
18
18
 
19
- unless ENV['localwiki_client_user'] && ENV['localwiki_client_apikey']
19
+ unless ENV['localwiki_client_server'] && ENV['localwiki_client_user'] && ENV['localwiki_client_apikey']
20
20
  puts "\nTo add or modify tests in the spec folder you need to do two things:"
21
- puts "\tContact sethvincent@gmail.com to request a username and apikey on the test server."
22
- puts "\tSet these two environment variables:\n\t\texport localwiki_client_user=USERNAME\n\t\texport localwiki_client_apikey=APIKEY"
21
+ puts "\tContact a test server admin to request the hostname, and a username / apikey for your test server."
22
+ puts "\tSet these three environment variables (working example given):"
23
+ puts "\t\texport localwiki_client_server=ec2-54-234-151-52.compute-1.amazonaws.com"
24
+ puts "\t\texport localwiki_client_user=testuser"
25
+ puts "\t\texport localwiki_client_apikey=1ff0ed07625365b8d5589f17088f43b5ae227793"
23
26
  end
@@ -4,7 +4,7 @@ describe 'LocalwikiClient' do
4
4
 
5
5
  before(:all) do
6
6
  VCR.insert_cassette 'list', :record => :new_episodes
7
- @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
7
+ @wiki = Localwiki::Client.new ENV['localwiki_client_server'],
8
8
  ENV['localwiki_client_user'],
9
9
  ENV['localwiki_client_apikey']
10
10
  require 'securerandom'
@@ -4,7 +4,7 @@ describe 'LocalwikiClient' do
4
4
 
5
5
  before(:all) do
6
6
  VCR.insert_cassette 'localwiki_client', :record => :new_episodes
7
- @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com'
7
+ @wiki = Localwiki::Client.new ENV['localwiki_client_server']
8
8
  end
9
9
 
10
10
  after(:all) do
@@ -4,7 +4,7 @@ describe 'LocalwikiClient' do
4
4
 
5
5
  before(:all) do
6
6
  VCR.insert_cassette 'slug', :record => :new_episodes
7
- @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
7
+ @wiki = Localwiki::Client.new ENV['localwiki_client_server'],
8
8
  ENV['localwiki_client_user'],
9
9
  ENV['localwiki_client_apikey']
10
10
  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.3.0
4
+ version: 0.3.1
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-29 00:00:00.000000000 Z
12
+ date: 2013-04-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday_middleware
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: json_pure
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -213,6 +227,8 @@ files:
213
227
  - History.txt
214
228
  - README.md
215
229
  - Rakefile
230
+ - examples/localwiki_stats.rb
231
+ - examples/nearby_wiki_pages.rb
216
232
  - integration/helper.rb
217
233
  - integration/live_saltlake_wiki_spec.rb
218
234
  - integration/live_test_wiki_spec.rb
@@ -258,7 +274,7 @@ homepage: http://github.com/bfaloona/localwiki_client
258
274
  licenses:
259
275
  - MIT
260
276
  metadata: {}
261
- post_install_message: "\n Thank you for installing localwiki_client 0.3.0\n "
277
+ post_install_message: "\n Thank you for installing localwiki_client 0.3.1\n "
262
278
  rdoc_options:
263
279
  - --charset=UTF-8
264
280
  require_paths:
@@ -278,6 +294,6 @@ rubyforge_project:
278
294
  rubygems_version: 2.0.0
279
295
  signing_key:
280
296
  specification_version: 4
281
- summary: localwiki_client-0.3.0
297
+ summary: localwiki_client-0.3.1
282
298
  test_files: []
283
299
  has_rdoc: