hcanzl_test_localwiki_client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .idea
2
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'rspec', :cli => "--color --format d" do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { "spec" }
4
+ watch('spec/helper.rb') { "spec" }
5
+ end
6
+
data/History.txt ADDED
@@ -0,0 +1,17 @@
1
+ === 0.0.4 / 2013-01-05
2
+
3
+ * Fixed gem homepage
4
+
5
+ === 0.0.3 / 2013-01-05
6
+
7
+ * Renamed to localwiki_client
8
+ * #total_resources now uses &limit=1
9
+ * #page_by_name
10
+
11
+ === 0.0.2 / 2013-01-03
12
+
13
+ * Path and docs fixes
14
+
15
+ === 0.0.1 / 2013-01-03
16
+
17
+ * It's Alive!
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ LocalwikiClient
2
+ ===============
3
+ [![Build Status](https://travis-ci.org/codeforseattle/localwiki_client.png?branch=master)](https://travis-ci.org/codeforseattle/localwiki_client) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/codeforseattle/localwiki_client)
4
+
5
+ Synopsis
6
+ --------
7
+
8
+ A thin client for the Localwiki API
9
+
10
+ http://localwiki.readthedocs.org/en/latest/api.html
11
+
12
+ Installation
13
+ ------------
14
+
15
+ $ gem install localwiki_client
16
+
17
+ Usage
18
+ -----
19
+
20
+ ## Example
21
+
22
+ require 'localwiki_client'
23
+ wiki = LocalwikiClient.new 'seattlewiki.net'
24
+ wiki.site_name
25
+ => SeattleWiki
26
+ wiki.count('user')
27
+ => 47
28
+
29
+ Compatibility
30
+ -------------
31
+ * 1.9.3
32
+ * jruby-19mode
33
+ * rbx-19mode
34
+
35
+ Contributing
36
+ ------------
37
+
38
+ To get your improvements included, please fork and submit a pull request.
39
+ Bugs and/or failing tests are very appreciated.
40
+
41
+ LICENSE
42
+ -------
43
+
44
+ (The MIT License)
45
+
46
+ Copyright (c) 2013 Brandon Faloona, Seth Vincent
47
+
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of this software and associated documentation files (the
50
+ 'Software'), to deal in the Software without restriction, including
51
+ without limitation the rights to use, copy, modify, merge, publish,
52
+ distribute, sublicense, and/or sell copies of the Software, and to
53
+ permit persons to whom the Software is furnished to do so, subject to
54
+ the following conditions:
55
+
56
+ The above copyright notice and this permission notice shall be
57
+ included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
60
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
61
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
62
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
63
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
64
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
65
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ require 'rake'
2
+ require 'rspec/core'
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run unit test specs'
6
+ task :default => :spec
7
+
8
+ desc 'Run all tests'
9
+ task :all => [:spec, :integration, :flog_detail]
10
+
11
+ desc "Run unit test specs"
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = "./spec/*_spec.rb"
14
+ t.rspec_opts = ['-f d']
15
+ end
16
+
17
+ desc "Run unit test specs"
18
+ task :test => [:spec]
19
+
20
+ desc "Run integration tests"
21
+ RSpec::Core::RakeTask.new(:integration) do |t|
22
+ t.pattern = "spec/integration/*_spec.rb"
23
+ t.rspec_opts = ['-f d']
24
+ end
25
+
26
+ desc "Flog the code! (*nix only)"
27
+ task :flog do
28
+ system('find lib -name \*.rb | xargs flog')
29
+ end
30
+
31
+ desc "Detailed Flog report! (*nix only)"
32
+ task :flog_detail do
33
+ system('find lib -name \*.rb | xargs flog -d')
34
+ end
@@ -0,0 +1,152 @@
1
+ require 'faraday'
2
+ require 'json/pure'
3
+
4
+ module Localwiki
5
+
6
+ ##
7
+ # A client that wraps the localwiki api for a given server instance
8
+ #
9
+ class Client
10
+
11
+ attr_accessor :hostname # hostname of the server we'd like to point at
12
+ attr_reader :site_name # site resource - display name of wiki
13
+ attr_reader :time_zone # site resource - time zone of server, e.g. 'America/Chicago'
14
+ attr_reader :language_code # site resource - language code of the server, e.g. 'en-us'
15
+
16
+ ##
17
+ # Create a LocalWikiClient instance
18
+ #
19
+ # @example LocalwikiClient.new 'seattlewiki.net'
20
+ #
21
+ def initialize hostname, user=nil, apikey=nil
22
+ @hostname = hostname
23
+ @user = user
24
+ @apikey = apikey
25
+ create_connection
26
+ collect_site_details
27
+ end
28
+
29
+ ##
30
+ # Request total count of given resource
31
+ #
32
+ def count(resource)
33
+ list(resource.to_s,1)["meta"]["total_count"]
34
+ end
35
+
36
+ ##
37
+ # fetch a page by name ("The Page Name" or "The_Page_Name" or "the page name")
38
+ # @param name "The Page Name" or "The_Page_Name" or "the page name"
39
+ def page_by_name(name)
40
+ fetch(:page,"#{name.gsub!(/\s/, '_')}")
41
+ end
42
+
43
+ ##
44
+ # list of a specific type of resource
45
+ # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
46
+ # @param limit is an integer
47
+ # @param is a hash of query string params
48
+ def list(resource,limit=0,params={})
49
+ uri = '/api/' + resource.to_s
50
+ params.merge!({limit: limit.to_s})
51
+ http_get(uri,params)
52
+ end
53
+
54
+ ##
55
+ # fetch a specific resource
56
+ # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
57
+ # identifier is id, pagename, slug, etc.
58
+ # params is a hash of query string params
59
+ def fetch(resource,identifier,params={})
60
+ uri = '/api/' + resource.to_s + '/' + identifier
61
+ http_get(uri,params)
62
+ end
63
+
64
+ ##
65
+ # create a specific resource
66
+ # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
67
+ def create(resource, json)
68
+ uri = '/api/' + resource.to_s + '/'
69
+ http_post(uri, json)
70
+ end
71
+
72
+ ##
73
+ # update a specific resource
74
+ # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
75
+ # identifier is id, pagename, slug, etc.
76
+ def update(resource,identifier,json)
77
+ uri = '/api/' + resource.to_s + '/' + identifier
78
+ http_put(uri, json)
79
+ end
80
+
81
+ ##
82
+ # delete a specific resource
83
+ # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
84
+ # identifier is id, pagename, slug, etc.
85
+ def delete(resource,identifier)
86
+ uri = '/api/' + resource.to_s + '/' + identifier
87
+ http_delete(uri)
88
+ end
89
+
90
+ private
91
+
92
+ ##
93
+ # Get site resource and set instance variables
94
+ #
95
+ def collect_site_details
96
+ site = fetch('site','1')
97
+ @site_name = site['name']
98
+ @time_zone = site['time_zone']
99
+ @language_code = site['language_code']
100
+ end
101
+
102
+ ##
103
+ # create Faraday::Connection instance and set @site
104
+ #
105
+ def create_connection
106
+ @site = Faraday.new :url => @hostname
107
+ end
108
+
109
+ ##
110
+ # http get request
111
+ # url is formatted as http://[@hostname]/[thing(s)-you-want]?[params]
112
+ #
113
+ def http_get(uri,params={})
114
+ params.merge!({format: 'json'})
115
+ full_url = 'http://' + @hostname + uri.to_s
116
+ response = @site.get full_url, params
117
+ JSON.parse(response.body)
118
+ end
119
+
120
+ def http_post(uri, json)
121
+ full_url = 'http://' + @hostname + uri.to_s
122
+
123
+ @site.post do |req|
124
+ req.url full_url
125
+ req.headers['Content-Type'] = 'application/json'
126
+ req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
127
+ req.body = json
128
+ end
129
+ end
130
+
131
+ def http_put(uri, json)
132
+ full_url = 'http://' + @hostname + uri.to_s
133
+
134
+ @site.put do |req|
135
+ req.url full_url
136
+ req.headers['Content-Type'] = 'application/json'
137
+ req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
138
+ req.body = json
139
+ end
140
+ end
141
+
142
+ def http_delete(uri)
143
+ full_url = 'http://' + @hostname + uri.to_s
144
+
145
+ @site.delete do |req|
146
+ req.url full_url
147
+ req.headers['Content-Type'] = 'application/json'
148
+ req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
149
+ end
150
+ end
151
+ end
152
+ end
@@ -0,0 +1,5 @@
1
+ module Localwiki
2
+
3
+ VERSION = '0.1.0'
4
+
5
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__)) unless
2
+ $LOAD_PATH.include?(File.dirname(__FILE__)) || $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'localwiki/client'
5
+ require 'localwiki/version'
6
+
7
+ # convenience class
8
+ class LocalwikiClient < Localwiki::Client; end
Binary file
@@ -0,0 +1,41 @@
1
+ $LOAD_PATH.unshift(File.expand_path('./lib', File.dirname(__FILE__)))
2
+ require 'localwiki/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'hcanzl_test_localwiki_client'
6
+ s.version = Localwiki::VERSION
7
+ s.authors = ["Brandon Faloona", "Seth Vincent"]
8
+ s.description = %{ A thin client that wraps the Localwiki API. }
9
+ s.summary = "localwiki_client-#{s.version}"
10
+ s.email = 'brandon@faloona.net'
11
+ s.homepage = "http://github.com/bfaloona/localwiki_client"
12
+ s.license = 'MIT'
13
+ s.platform = Gem::Platform::RUBY
14
+ s.required_ruby_version = '>= 1.9.2'
15
+
16
+ s.add_dependency('faraday')
17
+ s.add_dependency('json')
18
+
19
+ s.add_development_dependency('rake')
20
+ s.add_development_dependency('rspec', '>= 2.9.0')
21
+ s.add_development_dependency('rspec-mocks', '>= 2.9.0')
22
+ s.add_development_dependency('rb-fsevent')
23
+
24
+ unless ENV['TRAVIS'] == 'true'
25
+ s.add_development_dependency('flog')
26
+ s.add_development_dependency('guard')
27
+ unless ENV['RUBY_VERSION'] && ENV['RUBY_VERSION'].match(/jruby|rbx/)
28
+ s.add_development_dependency('guard-rspec')
29
+ end
30
+ end
31
+
32
+
33
+ s.post_install_message =
34
+ %{
35
+ Thank you for installing localwiki_client #{s.version}
36
+ }
37
+
38
+ s.files = `git ls-files`.split("\n")
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_path = "lib"
41
+ end
@@ -0,0 +1,9 @@
1
+ {
2
+ "content": "<p>\n\t </p>\n<table class=\"details\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Location</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t<p>\n\t\t\t\t\t2918 Southwest Avalon Way</p>\n\t\t\t\t<p>\n\t\t\t\t\tSeattle, WA 98126</p>\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Hours</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t7am - 10pm Everyday</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Phone</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t(206) 935-7250</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Website</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t<a href=\"http://www.lunaparkcafe.com/\">lunaparkcafe.com</a></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Established</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\tMarch 18th, 1989</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Price range</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t$10</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Payment Methods</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\tCash, credit cards</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td style=\"background-color: rgb(232, 236, 239);\">\n\t\t\t\t<strong>Wheelchair accessibility</strong></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\tNo stairs.</td>\n\t\t</tr>\n\t</tbody>\n</table>\n<p>\n\tFantastic diner filled with historic references to the Luna Park amusement park.</p>\n<p>\n\t<span class=\"image_frame image_frame_border\"><img src=\"_files/luna_park_cafe_front.jpg\" style=\"width: 300px; height: 225px;\"></span><span class=\"image_frame image_frame_border\"><img src=\"_files/luna_park_cafe_batmobile_ride.jpg\" style=\"width: 300px; height: 225px;\"></span></p>\n<h3>\n\tRelated Links</h3>\n<ul>\n\t<li>\n\t\t<a href=\"Restaurants\">Restaurants</a></li>\n</ul>\n<p>\n\t </p>\n",
3
+ "id": 572,
4
+ "map": "/api/map/Luna_Park_Cafe",
5
+ "name": "Luna Park Cafe",
6
+ "page_tags": "/api/page_tags/Luna_Park_Cafe",
7
+ "resource_uri": "/api/page/Luna_Park_Cafe",
8
+ "slug": "luna park cafe"
9
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "domain": "mockwiki.foo",
3
+ "id": 1,
4
+ "language_code": "en-us",
5
+ "license": "<p>Except where otherwise noted, this content is licensed under a <a rel=\" license\" href=\"http://creativecommons.org/licenses/by/3.0/\">Creative Commons Attribution License</a>. See <a href=\"/Copyrights\">Copyrights.</p>",
6
+ "name": "Salt Lake Wiki",
7
+ "resource_uri": "/api/site/1",
8
+ "signup_tos": "I agree to release my contributions under the <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/\" target=\"_blank\">Creative Commons-By license</a>, unless noted otherwise. See <a href=\"/Copyrights\" target=\"_blank\">Copyrights</a>.",
9
+ "time_zone": "America/Chicago"
10
+ }
@@ -0,0 +1,18 @@
1
+ {"meta": {
2
+ "limit": 20,
3
+ "next": null,
4
+ "offset": 0,
5
+ "previous": null,
6
+ "total_count": 1
7
+ }, "objects": [
8
+ {
9
+ "domain": "seattlewiki.net",
10
+ "id": 1,
11
+ "language_code": "en-us",
12
+ "license": "<p>Except where otherwise noted, this content is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/\">Creative Commons Attribution License</a>. See <a href=\"/Copyrights\">Copyrights.</p>",
13
+ "name": "SeattleWiki",
14
+ "resource_uri": "/api/site/1",
15
+ "signup_tos": "I agree to release my contributions under the <a rel=\"license\" href=\"http://creativecommons.org/licenses/by/3.0/\" target=\"_blank\">Creative Commons-By license</a>, unless noted otherwise. See <a href=\"/Copyrights\" target=\"_blank\">Copyrights</a>.",
16
+ "time_zone": "America/Chicago"
17
+ }
18
+ ]}
@@ -0,0 +1,49 @@
1
+ {
2
+ "meta": {
3
+ "limit": 0,
4
+ "offset": 0,
5
+ "total_count": 6
6
+ }, "objects": [
7
+ {
8
+ "date_joined": "2012-10-05T21:12:34.103559",
9
+ "first_name": "",
10
+ "last_name": "",
11
+ "resource_uri": "",
12
+ "username": "AnonymousUser"
13
+ },
14
+ {
15
+ "date_joined": "2012-11-02T15:24:44.621040",
16
+ "first_name": "Lou",
17
+ "last_name": "Davis",
18
+ "resource_uri": "/api/user/3",
19
+ "username": "loudavis"
20
+ },
21
+ {
22
+ "date_joined": "2012-10-17T14:01:40.778496",
23
+ "first_name": "Tod",
24
+ "last_name": "Davis",
25
+ "resource_uri": "/api/user/2",
26
+ "username": "toddavis"
27
+ },
28
+ {
29
+ "date_joined": "2012-11-20T21:47:33.152069",
30
+ "first_name": "Jessie",
31
+ "last_name": "Me",
32
+ "resource_uri": "/api/user/4",
33
+ "username": "jessieme"
34
+ },
35
+ {
36
+ "date_joined": "2012-10-05T21:12:33",
37
+ "first_name": "Andrew",
38
+ "last_name": "Drew",
39
+ "resource_uri": "/api/user/1",
40
+ "username": "andrewdrew"
41
+ },
42
+ {
43
+ "date_joined": "2012-12-08T15:33:29.251275",
44
+ "first_name": "Ryan",
45
+ "last_name": "Buyin",
46
+ "resource_uri": "/api/user/5",
47
+ "username": "ryanbuyin"
48
+ }
49
+ ]}
data/spec/helper.rb ADDED
@@ -0,0 +1,9 @@
1
+
2
+ def load_json filename
3
+ File.open(File.expand_path("../data", __FILE__) + "/#{filename}", 'r').read
4
+ end
5
+
6
+ def test_env_vars_set?
7
+ return true if ENV['localwiki_client_user'] && ENV['localwiki_client_apikey']
8
+ puts "\nSet these two environment variables to test #create\n\texport localwiki_client_user=USERNAME\n\texport localwiki_client_apikey=APIKEY"
9
+ end
@@ -0,0 +1,20 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require 'localwiki_client'
3
+
4
+ describe 'LIVE saltlakewiki.org' do
5
+
6
+ subject { Localwiki::Client.new 'saltlakewiki.org' }
7
+
8
+ context '#time_zone' do
9
+ it {subject.time_zone.should eq 'America/Chicago' }
10
+ end
11
+
12
+ context '#language_code' do
13
+ it {subject.language_code.should eq 'en-us'}
14
+ end
15
+
16
+ context '#total_resources("user")' do
17
+ it {subject.count('user').to_i.should > 2}
18
+ end
19
+
20
+ end
@@ -0,0 +1,33 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require File.expand_path("../../helper", __FILE__)
3
+ require 'localwiki_client'
4
+
5
+ if test_env_vars_set?
6
+
7
+ describe 'LIVE testwiki instance' do
8
+
9
+ before(:all) {
10
+ @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
11
+ ENV['localwiki_client_user'],
12
+ ENV['localwiki_client_apikey']
13
+ }
14
+
15
+ context '#time_zone' do
16
+ it {@wiki.time_zone.should eq 'America/Chicago' }
17
+ end
18
+
19
+ context "#create('page', 'TestPage<uuid>')" do
20
+
21
+ it 'response.status is 201' do
22
+ require 'securerandom'
23
+ pagename = "TestPage#{SecureRandom.uuid}"
24
+ response = @wiki.create('page', pagename, {})
25
+ response.status.should eq 201
26
+ # puts response.headers.inspect
27
+ # puts response.headers["location"]
28
+ end
29
+
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'localwiki_client'
3
+ require 'rspec/mocks'
4
+ require 'helper'
5
+
6
+ describe 'LocalwikiClient convenience class' do
7
+
8
+ context 'initialize' do
9
+
10
+ before(:all) do
11
+ @site_fetch_json = load_json 'site_fetch.json'
12
+ end
13
+
14
+ before(:each) do
15
+ response = double('response')
16
+ response.stub(:body) { @site_fetch_json }
17
+ conn = double('conn')
18
+ Faraday.should_receive(:new
19
+ ).with(
20
+ { url: 'mockwiki.foo' }
21
+ ).and_return(conn)
22
+ # Faraday::Connection.any_instance
23
+ conn.should_receive(:get
24
+ ).with(
25
+ 'http://mockwiki.foo/api/site/1',
26
+ {format: 'json'}
27
+ ).and_return(response)
28
+ end
29
+
30
+ subject { LocalwikiClient.new 'mockwiki.foo' }
31
+
32
+ context '#site_name' do
33
+ it { subject.site_name.should eq 'Salt Lake Wiki' }
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'localwiki_client'
3
+ require 'rspec/mocks'
4
+ require 'helper'
5
+
6
+ describe Localwiki::Client do
7
+
8
+ context 'page create' do
9
+
10
+ before(:all) do
11
+ @site_fetch_json = load_json 'site_fetch.json'
12
+ end
13
+
14
+ subject { Localwiki::Client.new 'mockwiki.foo', 'wikiuser', 'ab1234ab1324ab1234' }
15
+
16
+ context "#create('page', 'A New Page')" do
17
+ it 'response.status is 201' do
18
+ pending 'Need a better test framework'
19
+ stubs = Faraday::Adapter::Test::Stubs.new do |stub|
20
+ stub.get('/api/site/1') { [200, {}, 'egg'] }
21
+ stub.post('/api/page') { [201, {}, 'egg'] }
22
+ end
23
+ subject.create('page', 'A New Page', {}).should eq 'http://mockwiki.foo/A_New_Page'
24
+ end
25
+ end
26
+
27
+ end
28
+ end
data/spec/page_spec.rb ADDED
@@ -0,0 +1,41 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'localwiki_client'
3
+ require 'rspec/mocks'
4
+ require 'helper'
5
+
6
+ describe Localwiki::Client do
7
+
8
+ context 'page' do
9
+
10
+ before(:all) do
11
+ @site_fetch_json = load_json 'site_fetch.json'
12
+ end
13
+
14
+ subject { Localwiki::Client.new 'mockwiki.foo' }
15
+
16
+ context "#page_by_name('Luna Park Cafe')" do
17
+ it 'has content matching "amusement park"' do
18
+ response = double('response')
19
+ response.stub(:body) { @site_fetch_json }
20
+ conn = double('conn')
21
+ Faraday.should_receive(:new
22
+ ).with(
23
+ { url: 'mockwiki.foo' }
24
+ ).and_return(conn)
25
+ conn.should_receive(:get
26
+ ).with(
27
+ 'http://mockwiki.foo/api/site/1',
28
+ {format: 'json'}
29
+ ).and_return(response)
30
+ response1 = double('response1')
31
+ response1.stub(:body) { load_json 'page_fetch.json' }
32
+ conn.should_receive(:get
33
+ ).with(
34
+ 'http://mockwiki.foo/api/page/Luna_Park_Cafe', {format: 'json'}
35
+ ).and_return(response1)
36
+ subject.page_by_name('Luna Park Cafe')['content'].should match(/amusement park/)
37
+ end
38
+ end
39
+
40
+ end
41
+ end
data/spec/site_spec.rb ADDED
@@ -0,0 +1,48 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'localwiki_client'
3
+ require 'rspec/mocks'
4
+ require 'helper'
5
+
6
+ describe Localwiki::Client do
7
+
8
+ context 'site' do
9
+
10
+ before(:all) do
11
+ @site_fetch_json = load_json 'site_fetch.json'
12
+ end
13
+
14
+ before(:each) do
15
+ response = double('response')
16
+ response.stub(:body) { @site_fetch_json }
17
+ conn = double('conn')
18
+ Faraday.should_receive(:new
19
+ ).with(
20
+ { url: 'mockwiki.foo' }
21
+ ).and_return(conn)
22
+ # Faraday::Connection.any_instance
23
+ conn.should_receive(:get
24
+ ).with(
25
+ 'http://mockwiki.foo/api/site/1',
26
+ {format: 'json'}
27
+ ).and_return(response)
28
+ end
29
+
30
+ subject { Localwiki::Client.new 'mockwiki.foo' }
31
+
32
+ context 'attributes' do
33
+
34
+ context '#site_name' do
35
+ it { subject.site_name.should eq 'Salt Lake Wiki' }
36
+ end
37
+
38
+ context '#time_zone' do
39
+ it { subject.time_zone.should eq 'America/Chicago' }
40
+ end
41
+
42
+ context '#language_code' do
43
+ it { subject.language_code.should eq 'en-us'}
44
+ end
45
+
46
+ end
47
+ end
48
+ end
data/spec/user_spec.rb ADDED
@@ -0,0 +1,41 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ require 'localwiki_client'
3
+ require 'rspec/mocks'
4
+ require 'helper'
5
+
6
+ describe Localwiki::Client do
7
+
8
+ context 'user' do
9
+
10
+ before(:all) do
11
+ @site_fetch_json = load_json 'site_fetch.json'
12
+ end
13
+
14
+ subject { Localwiki::Client.new 'mockwiki.foo' }
15
+
16
+ context '#total_resources("user")' do
17
+ it 'should eq 6' do
18
+ response = double('response')
19
+ response.stub(:body) { @site_fetch_json }
20
+ conn = double('conn')
21
+ Faraday.should_receive(:new
22
+ ).with(
23
+ { url: 'mockwiki.foo' }
24
+ ).and_return(conn)
25
+ conn.should_receive(:get
26
+ ).with(
27
+ 'http://mockwiki.foo/api/site/1',
28
+ {format: 'json'}
29
+ ).and_return(response)
30
+ response1 = double('response1')
31
+ response1.stub(:body) { load_json 'user_list.json' }
32
+ conn.should_receive(:get
33
+ ).with(
34
+ 'http://mockwiki.foo/api/user', {format: 'json', limit: '1'}
35
+ ).and_return(response1)
36
+ subject.count('user').should eq 6
37
+ end
38
+ end
39
+
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,217 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hcanzl_test_localwiki_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Faloona
9
+ - Seth Vincent
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-02-25 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: faraday
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: json
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: 2.9.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: 2.9.0
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec-mocks
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 2.9.0
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 2.9.0
95
+ - !ruby/object:Gem::Dependency
96
+ name: rb-fsevent
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: flog
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: guard
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: guard-rspec
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :development
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description: ! ' A thin client that wraps the Localwiki API. '
160
+ email: brandon@faloona.net
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - .gitignore
166
+ - .rspec
167
+ - .travis.yml
168
+ - Gemfile
169
+ - Guardfile
170
+ - History.txt
171
+ - README.md
172
+ - Rakefile
173
+ - lib/localwiki/client.rb
174
+ - lib/localwiki/version.rb
175
+ - lib/localwiki_client.rb
176
+ - localwiki_client-0.0.4.gem
177
+ - localwiki_client.gemspec
178
+ - spec/data/page_fetch.json
179
+ - spec/data/site_fetch.json
180
+ - spec/data/site_list.json
181
+ - spec/data/user_list.json
182
+ - spec/helper.rb
183
+ - spec/integration/live_saltlake_wiki_spec.rb
184
+ - spec/integration/live_test_wiki_spec.rb
185
+ - spec/localwiki_client_spec.rb
186
+ - spec/page_create_spec.rb
187
+ - spec/page_spec.rb
188
+ - spec/site_spec.rb
189
+ - spec/user_spec.rb
190
+ homepage: http://github.com/bfaloona/localwiki_client
191
+ licenses:
192
+ - MIT
193
+ post_install_message: ! "\n Thank you for installing localwiki_client 0.1.0\n "
194
+ rdoc_options:
195
+ - --charset=UTF-8
196
+ require_paths:
197
+ - lib
198
+ required_ruby_version: !ruby/object:Gem::Requirement
199
+ none: false
200
+ requirements:
201
+ - - ! '>='
202
+ - !ruby/object:Gem::Version
203
+ version: 1.9.2
204
+ required_rubygems_version: !ruby/object:Gem::Requirement
205
+ none: false
206
+ requirements:
207
+ - - ! '>='
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ requirements: []
211
+ rubyforge_project:
212
+ rubygems_version: 1.8.24
213
+ signing_key:
214
+ specification_version: 3
215
+ summary: localwiki_client-0.1.0
216
+ test_files: []
217
+ has_rdoc: