localwiki_client 0.1.0 → 0.2.0
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.
- checksums.yaml +7 -0
 - data/.gitignore +2 -0
 - data/.travis.yml +2 -1
 - data/History.txt +11 -0
 - data/README.md +33 -0
 - data/Rakefile +19 -2
 - data/integration/helper.rb +9 -0
 - data/{spec/integration → integration}/live_saltlake_wiki_spec.rb +2 -2
 - data/integration/live_test_wiki_spec.rb +47 -0
 - data/lib/localwiki/client.rb +131 -38
 - data/lib/localwiki/version.rb +1 -1
 - data/localwiki_client.gemspec +6 -2
 - data/spec/basic_crud_spec.rb +67 -0
 - data/spec/basic_spec.rb +34 -0
 - data/spec/fetch_version_spec.rb +43 -0
 - data/spec/fixtures/cassettes/basic.yml +91 -0
 - data/spec/fixtures/cassettes/basic_crud.yml +90 -0
 - data/spec/fixtures/cassettes/basic_crud_delete_fail.yml +42 -0
 - data/spec/fixtures/cassettes/basic_crud_delete_success.yml +42 -0
 - data/spec/fixtures/cassettes/basic_crud_read_fail.yml +52 -0
 - data/spec/fixtures/cassettes/basic_crud_read_success.yml +40 -0
 - data/spec/fixtures/cassettes/basic_crud_update_success.yml +42 -0
 - data/spec/fixtures/cassettes/basic_fetch_version_success.yml +130 -0
 - data/spec/fixtures/cassettes/basic_page_by_name_spaces.yml +41 -0
 - data/spec/fixtures/cassettes/basic_unique_authors_success.yml +130 -0
 - data/spec/fixtures/cassettes/fetch.yml +46 -0
 - data/spec/fixtures/cassettes/localwiki_client.yml +366 -0
 - data/spec/fixtures/cassettes/slug.yml +46 -0
 - data/spec/helper.rb +15 -3
 - data/spec/localwiki_client_spec.rb +31 -25
 - data/spec/slug_spec.rb +26 -0
 - metadata +100 -61
 - data/localwiki_client-0.0.4.gem +0 -0
 - data/spec/data/page_fetch.json +0 -9
 - data/spec/data/site_fetch.json +0 -10
 - data/spec/data/site_list.json +0 -18
 - data/spec/data/user_list.json +0 -49
 - data/spec/page_spec.rb +0 -41
 - data/spec/site_spec.rb +0 -48
 - data/spec/user_spec.rb +0 -41
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA1:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 57676e3cee0822abe0c07ab173531579f1cccb21
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: c7b7b0370f9372cca7b2149e0374737a04fca115
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9a420a1750d4d72858603feff2eeb7656e27649526b5138eeffb8d933fc685e5de239515df86f2cbaed82e46c1b760c0d28b18122d1816f27d34f1218fcc0a9c
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 254a56caf270b691b689ea326f8d3000ebe211aedfece5b411646f9609997ccc06c9caefe0b03d1ecbe80c322cdac7a17b1f189c16288c918138fadc4d407bd9
         
     | 
    
        data/.gitignore
    CHANGED
    
    
    
        data/.travis.yml
    CHANGED
    
    
    
        data/History.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -20,14 +20,34 @@ Usage 
     | 
|
| 
       20 
20 
     | 
    
         
             
            ## Example
         
     | 
| 
       21 
21 
     | 
    
         | 
| 
       22 
22 
     | 
    
         
             
                require 'localwiki_client'
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                # read access
         
     | 
| 
       23 
25 
     | 
    
         
             
                wiki = LocalwikiClient.new 'seattlewiki.net'
         
     | 
| 
       24 
26 
     | 
    
         
             
                wiki.site_name
         
     | 
| 
       25 
27 
     | 
    
         
             
                => SeattleWiki
         
     | 
| 
       26 
28 
     | 
    
         
             
                wiki.count('user')
         
     | 
| 
       27 
29 
     | 
    
         
             
                => 47
         
     | 
| 
       28 
30 
     | 
    
         | 
| 
      
 31 
     | 
    
         
            +
                # write access
         
     | 
| 
      
 32 
     | 
    
         
            +
                wiki = LocalwikiClient.new 'seattlewiki.net', 'myusername', 'myapikey'
         
     | 
| 
      
 33 
     | 
    
         
            +
                page_json = {name: 'Current Events', content: 'Coming Soon!'}.to_json
         
     | 
| 
      
 34 
     | 
    
         
            +
                response = wiki.create('page', page_json)
         
     | 
| 
      
 35 
     | 
    
         
            +
                response.status
         
     | 
| 
      
 36 
     | 
    
         
            +
                => 201
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            Features / Problems
         
     | 
| 
      
 39 
     | 
    
         
            +
            -------------------
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            * #create, #read (#fetch), #update, #delete provide basic CRUD functionality
         
     | 
| 
      
 42 
     | 
    
         
            +
            * #list fetches all (or with a limit) of a specific type of resource
         
     | 
| 
      
 43 
     | 
    
         
            +
            * #fetch_version retrieves version history for a resource
         
     | 
| 
      
 44 
     | 
    
         
            +
            * a few helper methods exist, more to come
         
     | 
| 
      
 45 
     | 
    
         
            +
                * #count, #page_by_name, #unique_authors
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       29 
48 
     | 
    
         
             
            Compatibility
         
     | 
| 
       30 
49 
     | 
    
         
             
            -------------
         
     | 
| 
      
 50 
     | 
    
         
            +
             * 2.0.0
         
     | 
| 
       31 
51 
     | 
    
         
             
             * 1.9.3
         
     | 
| 
       32 
52 
     | 
    
         
             
             * jruby-19mode
         
     | 
| 
       33 
53 
     | 
    
         
             
             * rbx-19mode
         
     | 
| 
         @@ -36,8 +56,21 @@ Contributing 
     | 
|
| 
       36 
56 
     | 
    
         
             
            ------------
         
     | 
| 
       37 
57 
     | 
    
         | 
| 
       38 
58 
     | 
    
         
             
            To get your improvements included, please fork and submit a pull request.
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
       39 
60 
     | 
    
         
             
            Bugs and/or failing tests are very appreciated.
         
     | 
| 
       40 
61 
     | 
    
         | 
| 
      
 62 
     | 
    
         
            +
            Contributors
         
     | 
| 
      
 63 
     | 
    
         
            +
            ------------
         
     | 
| 
      
 64 
     | 
    
         
            +
            Seth Vincent
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            Brandon Faloona
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            Helen Canzler
         
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
            Jerry Frost
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            Matt Adkins
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
       41 
74 
     | 
    
         
             
            LICENSE
         
     | 
| 
       42 
75 
     | 
    
         
             
            -------
         
     | 
| 
       43 
76 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -1,6 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rake'
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'rspec/core'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'rspec/core/rake_task'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'yard'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            desc 'Default: run unit test specs'
         
     | 
| 
       6 
7 
     | 
    
         
             
            task :default => :spec
         
     | 
| 
         @@ -19,7 +20,7 @@ task :test => [:spec] 
     | 
|
| 
       19 
20 
     | 
    
         | 
| 
       20 
21 
     | 
    
         
             
            desc "Run integration tests"
         
     | 
| 
       21 
22 
     | 
    
         
             
            RSpec::Core::RakeTask.new(:integration) do |t|
         
     | 
| 
       22 
     | 
    
         
            -
              t.pattern = " 
     | 
| 
      
 23 
     | 
    
         
            +
              t.pattern = "integration/*_spec.rb"
         
     | 
| 
       23 
24 
     | 
    
         
             
              t.rspec_opts = ['-f d']
         
     | 
| 
       24 
25 
     | 
    
         
             
            end
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
         @@ -31,4 +32,20 @@ end 
     | 
|
| 
       31 
32 
     | 
    
         
             
            desc "Detailed Flog report! (*nix only)"
         
     | 
| 
       32 
33 
     | 
    
         
             
            task :flog_detail do
         
     | 
| 
       33 
34 
     | 
    
         
             
              system('find lib -name \*.rb | xargs flog -d')
         
     | 
| 
       34 
     | 
    
         
            -
            end
         
     | 
| 
      
 35 
     | 
    
         
            +
            end
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            desc "Generate YARD documentation for files in ['lib/**/*.rb']"
         
     | 
| 
      
 38 
     | 
    
         
            +
            YARD::Rake::YardocTask.new(:yard)
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
            desc "Delete VCR fixtures and logs"
         
     | 
| 
      
 41 
     | 
    
         
            +
            task :vcr_purge do
         
     | 
| 
      
 42 
     | 
    
         
            +
              files = Dir[File.expand_path("../spec/fixtures/cassettes/*", __FILE__)].map do |file|
         
     | 
| 
      
 43 
     | 
    
         
            +
                file if File.file?(file)
         
     | 
| 
      
 44 
     | 
    
         
            +
              end
         
     | 
| 
      
 45 
     | 
    
         
            +
              files.each { |file| File.delete(file) }
         
     | 
| 
      
 46 
     | 
    
         
            +
            end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
            desc "Sanitize VCR fixtures (remove Apikey values)"
         
     | 
| 
      
 49 
     | 
    
         
            +
            task :vcr_sanitize do
         
     | 
| 
      
 50 
     | 
    
         
            +
              system(%{ruby -pi -e "gsub(/- ApiKey .+:.+/, '- ApiKey testuser:key')" spec/fixtures/cassettes/*.yml})
         
     | 
| 
      
 51 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,9 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'localwiki_client'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            def test_env_vars_set?
         
     | 
| 
      
 5 
     | 
    
         
            +
              return true if ENV['localwiki_client_user'] && ENV['localwiki_client_apikey']
         
     | 
| 
      
 6 
     | 
    
         
            +
              puts "\nTo add or modify tests in the spec 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"
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path("../helper", __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            if test_env_vars_set?
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              describe 'LIVE testwiki instance' do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                before(:all) {
         
     | 
| 
      
 8 
     | 
    
         
            +
                  @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
         
     | 
| 
      
 9 
     | 
    
         
            +
                                                ENV['localwiki_client_user'],
         
     | 
| 
      
 10 
     | 
    
         
            +
                                                ENV['localwiki_client_apikey']
         
     | 
| 
      
 11 
     | 
    
         
            +
                  }
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                context "CRUD methods" do
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  before(:all) do
         
     | 
| 
      
 16 
     | 
    
         
            +
                    require 'securerandom'
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @pagename = "TestPage#{SecureRandom.uuid}"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  it "#create('page', json) response.status is 201" do
         
     | 
| 
      
 21 
     | 
    
         
            +
                    json = {name: @pagename, content: '<p>Created!</p>'}.to_json
         
     | 
| 
      
 22 
     | 
    
         
            +
                    response = @wiki.create('page', json)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    response.status.should eq 201
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  it "#read('page', 'TestPage<uuid>') response.status is 200" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                    response = @wiki.read('page', @pagename)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    response["content"].should match(/Created!/)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  it "#update('page', 'TestPage<uuid>', json) response.status is 204" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                    json = {content: '<p>Updated!</p>'}.to_json
         
     | 
| 
      
 33 
     | 
    
         
            +
                    response = @wiki.update('page', @pagename, json)
         
     | 
| 
      
 34 
     | 
    
         
            +
                    response.status.should eq 204
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @wiki.read('page', @pagename)["content"].should match(/Updated!/)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  it "#delete('page', 'TestPage<uuid>') response.status is 204" do
         
     | 
| 
      
 39 
     | 
    
         
            +
                    response = @wiki.delete('page', @pagename)
         
     | 
| 
      
 40 
     | 
    
         
            +
                    response.status.should eq 204
         
     | 
| 
      
 41 
     | 
    
         
            +
                    @wiki.read('page', @pagename).status.should eq 404
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/localwiki/client.rb
    CHANGED
    
    | 
         @@ -1,5 +1,5 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'faraday'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'json 
     | 
| 
      
 2 
     | 
    
         
            +
            require 'json'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Localwiki
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
         @@ -8,41 +8,54 @@ module Localwiki 
     | 
|
| 
       8 
8 
     | 
    
         
             
              #
         
     | 
| 
       9 
9 
     | 
    
         
             
              class Client
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
                 
     | 
| 
       12 
     | 
    
         
            -
                 
     | 
| 
       13 
     | 
    
         
            -
                 
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
      
 11 
     | 
    
         
            +
                # hostname of the server we'd like to point at
         
     | 
| 
      
 12 
     | 
    
         
            +
                attr_accessor :hostname
         
     | 
| 
      
 13 
     | 
    
         
            +
                
         
     | 
| 
      
 14 
     | 
    
         
            +
                # site resource - display name of wiki
         
     | 
| 
      
 15 
     | 
    
         
            +
                attr_reader   :site_name
         
     | 
| 
      
 16 
     | 
    
         
            +
                
         
     | 
| 
      
 17 
     | 
    
         
            +
                # site resource - time zone of server, example: 'America/Chicago'
         
     | 
| 
      
 18 
     | 
    
         
            +
                attr_reader   :time_zone      
         
     | 
| 
      
 19 
     | 
    
         
            +
                
         
     | 
| 
      
 20 
     | 
    
         
            +
                # site resource - language code of the server, example: 'en-us'
         
     | 
| 
      
 21 
     | 
    
         
            +
                attr_reader   :language_code  
         
     | 
| 
       15 
22 
     | 
    
         | 
| 
       16 
23 
     | 
    
         
             
                ##
         
     | 
| 
       17 
24 
     | 
    
         
             
                # Create a LocalWikiClient instance
         
     | 
| 
       18 
25 
     | 
    
         
             
                #
         
     | 
| 
       19 
     | 
    
         
            -
                # 
     | 
| 
      
 26 
     | 
    
         
            +
                # @example LocalwikiClient.new 'seattlewiki.net'
         
     | 
| 
       20 
27 
     | 
    
         
             
                #
         
     | 
| 
       21 
     | 
    
         
            -
                def initialize hostname
         
     | 
| 
      
 28 
     | 
    
         
            +
                def initialize hostname, user=nil, apikey=nil
         
     | 
| 
       22 
29 
     | 
    
         
             
                  @hostname = hostname
         
     | 
| 
      
 30 
     | 
    
         
            +
                  @user = user
         
     | 
| 
      
 31 
     | 
    
         
            +
                  @apikey = apikey
         
     | 
| 
       23 
32 
     | 
    
         
             
                  create_connection
         
     | 
| 
       24 
33 
     | 
    
         
             
                  collect_site_details
         
     | 
| 
       25 
34 
     | 
    
         
             
                end
         
     | 
| 
       26 
35 
     | 
    
         | 
| 
       27 
36 
     | 
    
         
             
                ##
         
     | 
| 
       28 
37 
     | 
    
         
             
                # Request total count of given resource
         
     | 
| 
       29 
     | 
    
         
            -
                #
         
     | 
| 
      
 38 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 39 
     | 
    
         
            +
                # @return [Fixnum] resource count
         
     | 
| 
      
 40 
     | 
    
         
            +
                # @example wiki.count('user')
         
     | 
| 
       30 
41 
     | 
    
         
             
                def count(resource)
         
     | 
| 
       31 
42 
     | 
    
         
             
                  list(resource.to_s,1)["meta"]["total_count"]
         
     | 
| 
       32 
43 
     | 
    
         
             
                end
         
     | 
| 
       33 
44 
     | 
    
         | 
| 
       34 
45 
     | 
    
         
             
                ##
         
     | 
| 
       35 
46 
     | 
    
         
             
                # fetch a page by name ("The Page Name" or "The_Page_Name" or "the page name")
         
     | 
| 
       36 
     | 
    
         
            -
                #
         
     | 
| 
      
 47 
     | 
    
         
            +
                # @param name "The Page Name" or "The_Page_Name" or "the page name"
         
     | 
| 
      
 48 
     | 
    
         
            +
                # @return [Hash] the parsed JSON object from the response body, otherwise the whole http response object
         
     | 
| 
       37 
49 
     | 
    
         
             
                def page_by_name(name)
         
     | 
| 
       38 
50 
     | 
    
         
             
                  fetch(:page,"#{name.gsub!(/\s/, '_')}")
         
     | 
| 
       39 
51 
     | 
    
         
             
                end
         
     | 
| 
       40 
52 
     | 
    
         | 
| 
       41 
53 
     | 
    
         
             
                ##
         
     | 
| 
       42 
54 
     | 
    
         
             
                # list of a specific type of resource
         
     | 
| 
       43 
     | 
    
         
            -
                # resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
       44 
     | 
    
         
            -
                # limit is an integer
         
     | 
| 
       45 
     | 
    
         
            -
                # params is a hash of query string params
         
     | 
| 
      
 55 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 56 
     | 
    
         
            +
                # @param limit is an integer
         
     | 
| 
      
 57 
     | 
    
         
            +
                # @param params is a hash of query string params
         
     | 
| 
      
 58 
     | 
    
         
            +
                # @return [Hash] the parsed JSON object from the response body, otherwise the whole http response object
         
     | 
| 
       46 
59 
     | 
    
         
             
                def list(resource,limit=0,params={})
         
     | 
| 
       47 
60 
     | 
    
         
             
                  uri = '/api/' + resource.to_s
         
     | 
| 
       48 
61 
     | 
    
         
             
                  params.merge!({limit: limit.to_s})
         
     | 
| 
         @@ -51,42 +64,79 @@ module Localwiki 
     | 
|
| 
       51 
64 
     | 
    
         | 
| 
       52 
65 
     | 
    
         
             
                ##
         
     | 
| 
       53 
66 
     | 
    
         
             
                # fetch a specific resource
         
     | 
| 
       54 
     | 
    
         
            -
                #  
     | 
| 
       55 
     | 
    
         
            -
                # identifier is id, pagename, slug, etc.
         
     | 
| 
       56 
     | 
    
         
            -
                # params is a hash of query string params
         
     | 
| 
      
 67 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 68 
     | 
    
         
            +
                # @param identifier is id, pagename, slug, etc.
         
     | 
| 
      
 69 
     | 
    
         
            +
                # @param params is a hash of query string params
         
     | 
| 
      
 70 
     | 
    
         
            +
                # @example wiki.update('page', '<page tag>')
         
     | 
| 
      
 71 
     | 
    
         
            +
                # @return [Hash] the parsed JSON object from the response body, otherwise the whole http response object
         
     | 
| 
       57 
72 
     | 
    
         
             
                def fetch(resource,identifier,params={})
         
     | 
| 
       58 
     | 
    
         
            -
                  uri = '/api/' + resource.to_s + '/' + identifier
         
     | 
| 
      
 73 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s + '/' + slugify(identifier)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  http_get(uri,params)
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
                alias_method :read, :fetch
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                ##
         
     | 
| 
      
 79 
     | 
    
         
            +
                # fetch version information for a resource
         
     | 
| 
      
 80 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 81 
     | 
    
         
            +
                # @param identifier is id, pagename, slug, etc.
         
     | 
| 
      
 82 
     | 
    
         
            +
                # @param params is a hash of query string params
         
     | 
| 
      
 83 
     | 
    
         
            +
                # @example wiki.fetch_version('page', 'First Page')
         
     | 
| 
      
 84 
     | 
    
         
            +
                # @return [Hash] the parsed JSON object from the response body, otherwise the whole http response object
         
     | 
| 
      
 85 
     | 
    
         
            +
                def fetch_version(resource,identifier,params={})
         
     | 
| 
      
 86 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s + '_version?name=' + identifier
         
     | 
| 
       59 
87 
     | 
    
         
             
                  http_get(uri,params)
         
     | 
| 
       60 
88 
     | 
    
         
             
                end
         
     | 
| 
       61 
89 
     | 
    
         | 
| 
      
 90 
     | 
    
         
            +
                ##
         
     | 
| 
      
 91 
     | 
    
         
            +
                # number of unique authors that have modified a resource
         
     | 
| 
      
 92 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 93 
     | 
    
         
            +
                # @param identifier is id, pagename, slug, etc.
         
     | 
| 
      
 94 
     | 
    
         
            +
                # @param params is a hash of query string params
         
     | 
| 
      
 95 
     | 
    
         
            +
                # @example wiki.unique_authors('page', 'First Page')
         
     | 
| 
      
 96 
     | 
    
         
            +
                # @return [Fixnum]
         
     | 
| 
      
 97 
     | 
    
         
            +
                def unique_authors(resource,identifier,params={})
         
     | 
| 
      
 98 
     | 
    
         
            +
                  json = fetch_version(resource,identifier,params)
         
     | 
| 
      
 99 
     | 
    
         
            +
                  json['objects'].map {|entry| entry['history_user']}.uniq.length
         
     | 
| 
      
 100 
     | 
    
         
            +
                end
         
     | 
| 
      
 101 
     | 
    
         
            +
             
     | 
| 
       62 
102 
     | 
    
         
             
                ##
         
     | 
| 
       63 
103 
     | 
    
         
             
                # create a specific resource
         
     | 
| 
       64 
     | 
    
         
            -
                #  
     | 
| 
       65 
     | 
    
         
            -
                 
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
      
 104 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 105 
     | 
    
         
            +
                # @param json is a json object
         
     | 
| 
      
 106 
     | 
    
         
            +
                # @example wiki.create('page', <json object containing the page tag>)
         
     | 
| 
      
 107 
     | 
    
         
            +
                # @return [HTTPResponse] the http response object
         
     | 
| 
      
 108 
     | 
    
         
            +
                def create(resource, json)
         
     | 
| 
      
 109 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s + '/'
         
     | 
| 
      
 110 
     | 
    
         
            +
                  http_post(uri, json)
         
     | 
| 
       67 
111 
     | 
    
         
             
                end
         
     | 
| 
       68 
112 
     | 
    
         | 
| 
       69 
113 
     | 
    
         
             
                ##
         
     | 
| 
       70 
114 
     | 
    
         
             
                # update a specific resource
         
     | 
| 
       71 
     | 
    
         
            -
                #  
     | 
| 
       72 
     | 
    
         
            -
                # identifier is id, pagename, slug, etc.
         
     | 
| 
      
 115 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 116 
     | 
    
         
            +
                # @param identifier is id, pagename, slug, etc.
         
     | 
| 
      
 117 
     | 
    
         
            +
                # @param json is a json object
         
     | 
| 
      
 118 
     | 
    
         
            +
                # @example wiki.update('page', '<page tag>', <json object>)
         
     | 
| 
      
 119 
     | 
    
         
            +
                # @return [HTTPResponse] the http response object
         
     | 
| 
       73 
120 
     | 
    
         
             
                def update(resource,identifier,json)
         
     | 
| 
       74 
     | 
    
         
            -
                   
     | 
| 
      
 121 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s + '/' + slugify(identifier)
         
     | 
| 
      
 122 
     | 
    
         
            +
                  http_put(uri, json)  
         
     | 
| 
       75 
123 
     | 
    
         
             
                end
         
     | 
| 
       76 
124 
     | 
    
         | 
| 
       77 
125 
     | 
    
         
             
                ##
         
     | 
| 
       78 
126 
     | 
    
         
             
                # delete a specific resource
         
     | 
| 
       79 
     | 
    
         
            -
                #  
     | 
| 
       80 
     | 
    
         
            -
                # identifier is id, pagename, slug, etc.
         
     | 
| 
      
 127 
     | 
    
         
            +
                # @param resource are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 128 
     | 
    
         
            +
                # @param identifier is id, pagename, slug, etc.
         
     | 
| 
      
 129 
     | 
    
         
            +
                # @example wiki.delete('page', '<page tag>')
         
     | 
| 
      
 130 
     | 
    
         
            +
                # @return [HTTPResponse] the http response object
         
     | 
| 
       81 
131 
     | 
    
         
             
                def delete(resource,identifier)
         
     | 
| 
       82 
     | 
    
         
            -
                   
     | 
| 
      
 132 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s + '/' + slugify(identifier)
         
     | 
| 
      
 133 
     | 
    
         
            +
                  http_delete(uri)
         
     | 
| 
       83 
134 
     | 
    
         
             
                end
         
     | 
| 
       84 
135 
     | 
    
         | 
| 
       85 
136 
     | 
    
         
             
                private
         
     | 
| 
       86 
137 
     | 
    
         | 
| 
       87 
138 
     | 
    
         
             
                ##
         
     | 
| 
       88 
139 
     | 
    
         
             
                # Get site resource and set instance variables
         
     | 
| 
       89 
     | 
    
         
            -
                #
         
     | 
| 
       90 
140 
     | 
    
         
             
                def collect_site_details
         
     | 
| 
       91 
141 
     | 
    
         
             
                  site = fetch('site','1')
         
     | 
| 
       92 
142 
     | 
    
         
             
                  @site_name = site['name']
         
     | 
| 
         @@ -96,32 +146,75 @@ module Localwiki 
     | 
|
| 
       96 
146 
     | 
    
         | 
| 
       97 
147 
     | 
    
         
             
                ##
         
     | 
| 
       98 
148 
     | 
    
         
             
                # create Faraday::Connection instance and set @site
         
     | 
| 
       99 
     | 
    
         
            -
                #
         
     | 
| 
       100 
149 
     | 
    
         
             
                def create_connection
         
     | 
| 
       101 
150 
     | 
    
         
             
                  @site = Faraday.new :url => @hostname
         
     | 
| 
       102 
151 
     | 
    
         
             
                end
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 152 
     | 
    
         
            +
              
         
     | 
| 
       104 
153 
     | 
    
         
             
                ##
         
     | 
| 
       105 
154 
     | 
    
         
             
                # http get request
         
     | 
| 
       106 
     | 
    
         
            -
                #  
     | 
| 
       107 
     | 
    
         
            -
                #
         
     | 
| 
      
 155 
     | 
    
         
            +
                # @param uri /api/<resource>/<resource identifier>
         
     | 
| 
      
 156 
     | 
    
         
            +
                # @param params is a hash of query string params
         
     | 
| 
      
 157 
     | 
    
         
            +
                # @return [Hash] the parsed JSON object, otherwise the  http response object
         
     | 
| 
       108 
158 
     | 
    
         
             
                def http_get(uri,params={})
         
     | 
| 
       109 
159 
     | 
    
         
             
                  params.merge!({format: 'json'})
         
     | 
| 
       110 
160 
     | 
    
         
             
                  full_url = 'http://' + @hostname + uri.to_s
         
     | 
| 
       111 
161 
     | 
    
         
             
                  response = @site.get full_url, params
         
     | 
| 
       112 
     | 
    
         
            -
                  JSON.parse(response.body)
         
     | 
| 
      
 162 
     | 
    
         
            +
                  JSON.parse(response.body) rescue response
         
     | 
| 
       113 
163 
     | 
    
         
             
                end
         
     | 
| 
       114 
     | 
    
         
            -
             
     | 
| 
       115 
     | 
    
         
            -
                 
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
      
 164 
     | 
    
         
            +
                
         
     | 
| 
      
 165 
     | 
    
         
            +
                ##
         
     | 
| 
      
 166 
     | 
    
         
            +
                # http post request
         
     | 
| 
      
 167 
     | 
    
         
            +
                # @param uri /api/<resource>/
         
     | 
| 
      
 168 
     | 
    
         
            +
                # @param json is a json object
         
     | 
| 
      
 169 
     | 
    
         
            +
                # @return [HTTPResponse] the http response object
         
     | 
| 
      
 170 
     | 
    
         
            +
                def http_post(uri, json)
         
     | 
| 
      
 171 
     | 
    
         
            +
                  full_url = 'http://' + @hostname + uri.to_s
         
     | 
| 
      
 172 
     | 
    
         
            +
                  
         
     | 
| 
      
 173 
     | 
    
         
            +
                  @site.post do |req|
         
     | 
| 
      
 174 
     | 
    
         
            +
                    req.url full_url
         
     | 
| 
      
 175 
     | 
    
         
            +
                    req.headers['Content-Type'] = 'application/json'
         
     | 
| 
      
 176 
     | 
    
         
            +
                    req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
         
     | 
| 
      
 177 
     | 
    
         
            +
                    req.body = json
         
     | 
| 
      
 178 
     | 
    
         
            +
                  end
         
     | 
| 
      
 179 
     | 
    
         
            +
                end
         
     | 
| 
      
 180 
     | 
    
         
            +
                
         
     | 
| 
      
 181 
     | 
    
         
            +
                ##
         
     | 
| 
      
 182 
     | 
    
         
            +
                # http put request
         
     | 
| 
      
 183 
     | 
    
         
            +
                # @param uri /api/<resource>/<resource identifier>
         
     | 
| 
      
 184 
     | 
    
         
            +
                # @param json is a json object
         
     | 
| 
      
 185 
     | 
    
         
            +
                # @return [HTTPResponse] the http response object
         
     | 
| 
      
 186 
     | 
    
         
            +
                def http_put(uri, json)
         
     | 
| 
      
 187 
     | 
    
         
            +
                  full_url = 'http://' + @hostname + uri.to_s
         
     | 
| 
      
 188 
     | 
    
         
            +
                  
         
     | 
| 
      
 189 
     | 
    
         
            +
                  @site.put do |req|
         
     | 
| 
      
 190 
     | 
    
         
            +
                    req.url full_url
         
     | 
| 
      
 191 
     | 
    
         
            +
                    req.headers['Content-Type'] = 'application/json'
         
     | 
| 
      
 192 
     | 
    
         
            +
                    req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
         
     | 
| 
      
 193 
     | 
    
         
            +
                    req.body = json
         
     | 
| 
      
 194 
     | 
    
         
            +
                  end
         
     | 
| 
       117 
195 
     | 
    
         
             
                end
         
     | 
| 
       118 
196 
     | 
    
         | 
| 
       119 
     | 
    
         
            -
                 
     | 
| 
       120 
     | 
    
         
            -
             
     | 
| 
      
 197 
     | 
    
         
            +
                ##
         
     | 
| 
      
 198 
     | 
    
         
            +
                # http delete request
         
     | 
| 
      
 199 
     | 
    
         
            +
                # @param uri /api/<resource>/<resource identifier>
         
     | 
| 
      
 200 
     | 
    
         
            +
                # @return [HTTPResponse] the http response object
         
     | 
| 
      
 201 
     | 
    
         
            +
                def http_delete(uri)
         
     | 
| 
      
 202 
     | 
    
         
            +
                  full_url = 'http://' + @hostname + uri.to_s
         
     | 
| 
      
 203 
     | 
    
         
            +
             
     | 
| 
      
 204 
     | 
    
         
            +
                  @site.delete do |req|
         
     | 
| 
      
 205 
     | 
    
         
            +
                    req.url full_url
         
     | 
| 
      
 206 
     | 
    
         
            +
                    req.headers['Content-Type'] = 'application/json'
         
     | 
| 
      
 207 
     | 
    
         
            +
                    req.headers['Authorization'] = "ApiKey #{@user}:#{@apikey}"
         
     | 
| 
      
 208 
     | 
    
         
            +
                  end
         
     | 
| 
       121 
209 
     | 
    
         
             
                end
         
     | 
| 
       122 
210 
     | 
    
         | 
| 
       123 
     | 
    
         
            -
                 
     | 
| 
       124 
     | 
    
         
            -
             
     | 
| 
      
 211 
     | 
    
         
            +
                ##
         
     | 
| 
      
 212 
     | 
    
         
            +
                # create human readable identifier that is used to create clean urls
         
     | 
| 
      
 213 
     | 
    
         
            +
                # @param string
         
     | 
| 
      
 214 
     | 
    
         
            +
                # @example slugify('My Page') == 'My_Page'
         
     | 
| 
      
 215 
     | 
    
         
            +
                # @return [String]
         
     | 
| 
      
 216 
     | 
    
         
            +
                def slugify(string)
         
     | 
| 
      
 217 
     | 
    
         
            +
                  string.to_s.strip.gsub(' ', "_")
         
     | 
| 
       125 
218 
     | 
    
         
             
                end
         
     | 
| 
       126 
219 
     | 
    
         | 
| 
       127 
220 
     | 
    
         
             
              end
         
     | 
    
        data/lib/localwiki/version.rb
    CHANGED
    
    
    
        data/localwiki_client.gemspec
    CHANGED
    
    | 
         @@ -14,11 +14,15 @@ 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(' 
     | 
| 
      
 17 
     | 
    
         
            +
              s.add_dependency('json_pure')
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
              s.add_development_dependency('rake')
         
     | 
| 
       20 
20 
     | 
    
         
             
              s.add_development_dependency('rspec', '>= 2.9.0')
         
     | 
| 
       21 
     | 
    
         
            -
              s.add_development_dependency(' 
     | 
| 
      
 21 
     | 
    
         
            +
              s.add_development_dependency('vcr')
         
     | 
| 
      
 22 
     | 
    
         
            +
              s.add_development_dependency('webmock', '>= 1.8.0', '< 1.10')
         
     | 
| 
      
 23 
     | 
    
         
            +
              s.add_development_dependency('yard')
         
     | 
| 
      
 24 
     | 
    
         
            +
              s.add_development_dependency('kramdown')
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
       22 
26 
     | 
    
         
             
              s.add_development_dependency('rb-fsevent')
         
     | 
| 
       23 
27 
     | 
    
         | 
| 
       24 
28 
     | 
    
         
             
              unless ENV['TRAVIS'] == 'true'
         
     | 
| 
         @@ -0,0 +1,67 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path("../helper", __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe 'LocalwikiClient' do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before(:all) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                VCR.insert_cassette 'basic_crud', :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 = "TestPage#{SecureRandom.uuid}"
         
     | 
| 
      
 12 
     | 
    
         
            +
                @path_matcher = lambda do |request_1, request_2|
         
     | 
| 
      
 13 
     | 
    
         
            +
                  URI(request_1.uri).path.match(/TestPage/) && URI(request_2.uri).path.match(/TestPage/)
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              after(:all) do
         
     | 
| 
      
 18 
     | 
    
         
            +
                VCR.eject_cassette
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              context "CRUD method" do
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                it "#create('page', json) response.status is 201" do
         
     | 
| 
      
 24 
     | 
    
         
            +
                  response = @wiki.create('page', {name: @pagename, content: '<p>Created!</p>'}.to_json)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  response.status.should eq 201
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                it "#read('page', pagename) response.status should match(/Created!/)" do
         
     | 
| 
      
 29 
     | 
    
         
            +
                  VCR.use_cassette 'basic_crud_read_success', :match_requests_on => [:method, @path_matcher] do
         
     | 
| 
      
 30 
     | 
    
         
            +
                    response = @wiki.read('page', @pagename)
         
     | 
| 
      
 31 
     | 
    
         
            +
                    response["content"].should match(/Created!/)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                it "#update('page', pagename, json) response.status is 204" do
         
     | 
| 
      
 36 
     | 
    
         
            +
                  VCR.use_cassette 'basic_crud_update_success', :match_requests_on => [:method, @path_matcher] do
         
     | 
| 
      
 37 
     | 
    
         
            +
                    response = @wiki.update('page', @pagename, {content: '<foo>'}.to_json)
         
     | 
| 
      
 38 
     | 
    
         
            +
                    response.status.should eq 204
         
     | 
| 
      
 39 
     | 
    
         
            +
                  end
         
     | 
| 
      
 40 
     | 
    
         
            +
                end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                it "#delete('page', pagename) response.status is 204" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  VCR.use_cassette 'basic_crud_delete_success', :match_requests_on => [:method, @path_matcher] do
         
     | 
| 
      
 44 
     | 
    
         
            +
                    response = @wiki.delete('page', @pagename)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    response.status.should eq 204
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                context "when page does not exist" do
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
                  it "#read returns response.status of 404" do
         
     | 
| 
      
 52 
     | 
    
         
            +
                    VCR.use_cassette 'basic_crud_read_fail', :match_requests_on => [:method, @path_matcher] do
         
     | 
| 
      
 53 
     | 
    
         
            +
                      response = @wiki.read('page', @pagename)
         
     | 
| 
      
 54 
     | 
    
         
            +
                      response.status.should eq 404
         
     | 
| 
      
 55 
     | 
    
         
            +
                    end
         
     | 
| 
      
 56 
     | 
    
         
            +
                  end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                  it "#delete returns response.status of 404" do
         
     | 
| 
      
 59 
     | 
    
         
            +
                    VCR.use_cassette 'basic_crud_delete_fail', :match_requests_on => [:method, @path_matcher] do
         
     | 
| 
      
 60 
     | 
    
         
            +
                      response = @wiki.delete('page', @pagename)
         
     | 
| 
      
 61 
     | 
    
         
            +
                      response.status.should eq 404
         
     | 
| 
      
 62 
     | 
    
         
            +
                    end
         
     | 
| 
      
 63 
     | 
    
         
            +
                  end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                end
         
     | 
| 
      
 66 
     | 
    
         
            +
              end
         
     | 
| 
      
 67 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/basic_spec.rb
    ADDED
    
    | 
         @@ -0,0 +1,34 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path("../helper", __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe 'LocalwikiClient' do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              context "#create and #page_by_name" do
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                before(:all) do
         
     | 
| 
      
 8 
     | 
    
         
            +
                  VCR.insert_cassette 'basic', :record => :new_episodes
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @wiki = Localwiki::Client.new 'ec2-54-234-151-52.compute-1.amazonaws.com',
         
     | 
| 
      
 10 
     | 
    
         
            +
                                                ENV['localwiki_client_user'],
         
     | 
| 
      
 11 
     | 
    
         
            +
                                                ENV['localwiki_client_apikey']
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                after(:all) do
         
     | 
| 
      
 15 
     | 
    
         
            +
                  VCR.eject_cassette
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                it "handle spaces" do
         
     | 
| 
      
 19 
     | 
    
         
            +
                  require 'securerandom'
         
     | 
| 
      
 20 
     | 
    
         
            +
                  base_name = "Test Page"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  page_name = "#{base_name}#{SecureRandom.uuid}"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  path_matcher = lambda do |request_1, request_2|
         
     | 
| 
      
 23 
     | 
    
         
            +
                    URI(request_1.uri).path.match(/Test/) && URI(request_2.uri).path.match(/Test/)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                  @wiki.create('page', {name: page_name, content: '<p>Created page with spaces!</p>'}.to_json)
         
     | 
| 
      
 26 
     | 
    
         
            +
                  VCR.use_cassette 'basic_page_by_name_spaces', :match_requests_on => [:method, path_matcher] do
         
     | 
| 
      
 27 
     | 
    
         
            +
                    response = @wiki.page_by_name(page_name)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    response["content"].should match(/Created page with spaces!/)
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,43 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require File.expand_path("../helper", __FILE__)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe 'LocalwikiClient' do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before(:all) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                VCR.insert_cassette 'fetch', :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 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              after(:all) do
         
     | 
| 
      
 14 
     | 
    
         
            +
                VCR.eject_cassette
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              context "#fetch_version" do
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                it "returns json that includes all edits" do
         
     | 
| 
      
 20 
     | 
    
         
            +
                  pagename = "TestPage#{SecureRandom.uuid}"
         
     | 
| 
      
 21 
     | 
    
         
            +
                  VCR.use_cassette 'basic_fetch_version_success', :match_requests_on => [:method] do
         
     | 
| 
      
 22 
     | 
    
         
            +
                    @wiki.create('page', {name: pagename, content: '<p>Created!</p>'}.to_json)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @wiki.update('page', pagename, {content: '<p>foo</p>'}.to_json)
         
     | 
| 
      
 24 
     | 
    
         
            +
                    response = @wiki.fetch_version('page', pagename)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    response['meta']['total_count'].should eq 2
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
                end
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              context "#unique_authors" do
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                it "returns the number of authors" do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  pagename = "TestPage#{SecureRandom.uuid}"
         
     | 
| 
      
 34 
     | 
    
         
            +
                  VCR.use_cassette 'basic_unique_authors_success', :match_requests_on => [:method] do
         
     | 
| 
      
 35 
     | 
    
         
            +
                    @wiki.create('page', {name: pagename, content: '<p>Created!</p>'}.to_json)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    @wiki.update('page', pagename, {content: '<p>foo</p>'}.to_json)
         
     | 
| 
      
 37 
     | 
    
         
            +
                    @wiki.unique_authors('page', pagename).should eq 1
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              end
         
     | 
| 
      
 42 
     | 
    
         
            +
            end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     |