localwiki_client 0.0.4 → 0.1.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.
- data/README.md +8 -1
 - data/Rakefile +8 -7
 - data/lib/localwiki/client.rb +128 -0
 - data/lib/localwiki/version.rb +5 -0
 - data/lib/localwiki_client.rb +7 -3
 - data/localwiki_client-0.0.4.gem +0 -0
 - data/localwiki_client.gemspec +6 -3
 - data/spec/data/page_fetch.json +9 -0
 - data/spec/data/site_fetch.json +10 -0
 - data/spec/data/site_list.json +18 -0
 - data/spec/data/user_list.json +49 -0
 - data/spec/helper.rb +4 -0
 - data/spec/integration/live_saltlake_wiki_spec.rb +2 -2
 - data/spec/localwiki_client_spec.rb +21 -58
 - data/spec/page_spec.rb +41 -0
 - data/spec/site_spec.rb +48 -0
 - data/spec/user_spec.rb +41 -0
 - metadata +17 -7
 - data/lib/localwiki_client/localwiki_client.rb +0 -70
 
    
        data/README.md
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            LocalwikiClient
         
     | 
| 
       2 
2 
     | 
    
         
             
            ===============
         
     | 
| 
      
 3 
     | 
    
         
            +
            [](https://travis-ci.org/codeforseattle/localwiki_client) [](https://codeclimate.com/github/codeforseattle/localwiki_client)
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            Synopsis
         
     | 
| 
       5 
6 
     | 
    
         
             
            --------
         
     | 
| 
         @@ -22,9 +23,15 @@ Usage 
     | 
|
| 
       22 
23 
     | 
    
         
             
                wiki = LocalwikiClient.new 'seattlewiki.net'
         
     | 
| 
       23 
24 
     | 
    
         
             
                wiki.site_name
         
     | 
| 
       24 
25 
     | 
    
         
             
                => SeattleWiki
         
     | 
| 
       25 
     | 
    
         
            -
                wiki. 
     | 
| 
      
 26 
     | 
    
         
            +
                wiki.count('user')
         
     | 
| 
       26 
27 
     | 
    
         
             
                => 47
         
     | 
| 
       27 
28 
     | 
    
         | 
| 
      
 29 
     | 
    
         
            +
            Compatibility
         
     | 
| 
      
 30 
     | 
    
         
            +
            -------------
         
     | 
| 
      
 31 
     | 
    
         
            +
             * 1.9.3
         
     | 
| 
      
 32 
     | 
    
         
            +
             * jruby-19mode
         
     | 
| 
      
 33 
     | 
    
         
            +
             * rbx-19mode
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       28 
35 
     | 
    
         
             
            Contributing
         
     | 
| 
       29 
36 
     | 
    
         
             
            ------------
         
     | 
| 
       30 
37 
     | 
    
         | 
    
        data/Rakefile
    CHANGED
    
    | 
         @@ -2,19 +2,20 @@ require 'rake' 
     | 
|
| 
       2 
2 
     | 
    
         
             
            require 'rspec/core'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'rspec/core/rake_task'
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            desc 'Default: run  
     | 
| 
       6 
     | 
    
         
            -
            task :default => : 
     | 
| 
      
 5 
     | 
    
         
            +
            desc 'Default: run unit test specs'
         
     | 
| 
      
 6 
     | 
    
         
            +
            task :default => :spec
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
            desc  
     | 
| 
      
 8 
     | 
    
         
            +
            desc 'Run all tests'
         
     | 
| 
      
 9 
     | 
    
         
            +
            task :all => [:spec, :integration, :flog_detail]
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            desc "Run unit test specs"
         
     | 
| 
       9 
12 
     | 
    
         
             
            RSpec::Core::RakeTask.new do |t|
         
     | 
| 
       10 
13 
     | 
    
         
             
              t.pattern = "./spec/*_spec.rb"
         
     | 
| 
       11 
14 
     | 
    
         
             
              t.rspec_opts = ['-f d']
         
     | 
| 
       12 
15 
     | 
    
         
             
            end
         
     | 
| 
       13 
16 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            desc "Run  
     | 
| 
       15 
     | 
    
         
            -
            task :test  
     | 
| 
       16 
     | 
    
         
            -
              Rake::Task['spec'].invoke
         
     | 
| 
       17 
     | 
    
         
            -
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
            desc "Run unit test specs"
         
     | 
| 
      
 18 
     | 
    
         
            +
            task :test => [:spec]
         
     | 
| 
       18 
19 
     | 
    
         | 
| 
       19 
20 
     | 
    
         
             
            desc "Run integration tests"
         
     | 
| 
       20 
21 
     | 
    
         
             
            RSpec::Core::RakeTask.new(:integration) do |t|
         
     | 
| 
         @@ -0,0 +1,128 @@ 
     | 
|
| 
      
 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 
     | 
    
         
            +
                #   LocalwikiClient.new 'seattlewiki.net'
         
     | 
| 
      
 20 
     | 
    
         
            +
                #
         
     | 
| 
      
 21 
     | 
    
         
            +
                def initialize hostname
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @hostname = hostname
         
     | 
| 
      
 23 
     | 
    
         
            +
                  create_connection
         
     | 
| 
      
 24 
     | 
    
         
            +
                  collect_site_details
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                ##
         
     | 
| 
      
 28 
     | 
    
         
            +
                # Request total count of given resource
         
     | 
| 
      
 29 
     | 
    
         
            +
                #
         
     | 
| 
      
 30 
     | 
    
         
            +
                def count(resource)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  list(resource.to_s,1)["meta"]["total_count"]
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                ##
         
     | 
| 
      
 35 
     | 
    
         
            +
                # fetch a page by name ("The Page Name" or "The_Page_Name" or "the page name")
         
     | 
| 
      
 36 
     | 
    
         
            +
                #
         
     | 
| 
      
 37 
     | 
    
         
            +
                def page_by_name(name)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  fetch(:page,"#{name.gsub!(/\s/, '_')}")
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                ##
         
     | 
| 
      
 42 
     | 
    
         
            +
                # 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
         
     | 
| 
      
 46 
     | 
    
         
            +
                def list(resource,limit=0,params={})
         
     | 
| 
      
 47 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s
         
     | 
| 
      
 48 
     | 
    
         
            +
                  params.merge!({limit: limit.to_s})
         
     | 
| 
      
 49 
     | 
    
         
            +
                  http_get(uri,params)
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                ##
         
     | 
| 
      
 53 
     | 
    
         
            +
                # fetch a specific resource
         
     | 
| 
      
 54 
     | 
    
         
            +
                # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 55 
     | 
    
         
            +
                # identifier is id, pagename, slug, etc.
         
     | 
| 
      
 56 
     | 
    
         
            +
                # params is a hash of query string params
         
     | 
| 
      
 57 
     | 
    
         
            +
                def fetch(resource,identifier,params={})
         
     | 
| 
      
 58 
     | 
    
         
            +
                  uri = '/api/' + resource.to_s + '/' + identifier
         
     | 
| 
      
 59 
     | 
    
         
            +
                  http_get(uri,params)
         
     | 
| 
      
 60 
     | 
    
         
            +
                end
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                ##
         
     | 
| 
      
 63 
     | 
    
         
            +
                # create a specific resource
         
     | 
| 
      
 64 
     | 
    
         
            +
                # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 65 
     | 
    
         
            +
                def create(resource,identifier,json)
         
     | 
| 
      
 66 
     | 
    
         
            +
                  raise 'Not Yet Implemented'
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                ##
         
     | 
| 
      
 70 
     | 
    
         
            +
                # update a specific resource
         
     | 
| 
      
 71 
     | 
    
         
            +
                # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 72 
     | 
    
         
            +
                # identifier is id, pagename, slug, etc.
         
     | 
| 
      
 73 
     | 
    
         
            +
                def update(resource,identifier,json)
         
     | 
| 
      
 74 
     | 
    
         
            +
                  raise 'Not Yet Implemented'
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                ##
         
     | 
| 
      
 78 
     | 
    
         
            +
                # delete a specific resource
         
     | 
| 
      
 79 
     | 
    
         
            +
                # resources are "site", "page", "user", "file", "map", "tag", "page_tag"
         
     | 
| 
      
 80 
     | 
    
         
            +
                # identifier is id, pagename, slug, etc.
         
     | 
| 
      
 81 
     | 
    
         
            +
                def delete(resource,identifier)
         
     | 
| 
      
 82 
     | 
    
         
            +
                  raise 'Not Yet Implemented'
         
     | 
| 
      
 83 
     | 
    
         
            +
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                private
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
                ##
         
     | 
| 
      
 88 
     | 
    
         
            +
                # Get site resource and set instance variables
         
     | 
| 
      
 89 
     | 
    
         
            +
                #
         
     | 
| 
      
 90 
     | 
    
         
            +
                def collect_site_details
         
     | 
| 
      
 91 
     | 
    
         
            +
                  site = fetch('site','1')
         
     | 
| 
      
 92 
     | 
    
         
            +
                  @site_name = site['name']
         
     | 
| 
      
 93 
     | 
    
         
            +
                  @time_zone = site['time_zone']
         
     | 
| 
      
 94 
     | 
    
         
            +
                  @language_code = site['language_code']
         
     | 
| 
      
 95 
     | 
    
         
            +
                end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                ##
         
     | 
| 
      
 98 
     | 
    
         
            +
                # create Faraday::Connection instance and set @site
         
     | 
| 
      
 99 
     | 
    
         
            +
                #
         
     | 
| 
      
 100 
     | 
    
         
            +
                def create_connection
         
     | 
| 
      
 101 
     | 
    
         
            +
                  @site = Faraday.new :url => @hostname
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                ##
         
     | 
| 
      
 105 
     | 
    
         
            +
                # http get request
         
     | 
| 
      
 106 
     | 
    
         
            +
                # url is formatted as http://[@hostname]/[thing(s)-you-want]?[params]
         
     | 
| 
      
 107 
     | 
    
         
            +
                #
         
     | 
| 
      
 108 
     | 
    
         
            +
                def http_get(uri,params={})
         
     | 
| 
      
 109 
     | 
    
         
            +
                  params.merge!({format: 'json'})
         
     | 
| 
      
 110 
     | 
    
         
            +
                  full_url = 'http://' + @hostname + uri.to_s
         
     | 
| 
      
 111 
     | 
    
         
            +
                  response = @site.get full_url, params
         
     | 
| 
      
 112 
     | 
    
         
            +
                  JSON.parse(response.body)
         
     | 
| 
      
 113 
     | 
    
         
            +
                end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                def http_post()
         
     | 
| 
      
 116 
     | 
    
         
            +
                  raise 'Not Yet Implemented'
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                def http_put()
         
     | 
| 
      
 120 
     | 
    
         
            +
                  raise 'Not Yet Implemented'
         
     | 
| 
      
 121 
     | 
    
         
            +
                end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                def http_delete()
         
     | 
| 
      
 124 
     | 
    
         
            +
                  raise 'Not Yet Implemented'
         
     | 
| 
      
 125 
     | 
    
         
            +
                end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
              end
         
     | 
| 
      
 128 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/localwiki_client.rb
    CHANGED
    
    | 
         @@ -1,4 +1,8 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
      
 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 
3 
     | 
    
         | 
| 
       4 
     | 
    
         
            -
            require ' 
     | 
| 
      
 4 
     | 
    
         
            +
            require 'localwiki/client'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'localwiki/version'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            # convenience class
         
     | 
| 
      
 8 
     | 
    
         
            +
            class LocalwikiClient < Localwiki::Client; end
         
     | 
| 
         Binary file 
     | 
    
        data/localwiki_client.gemspec
    CHANGED
    
    | 
         @@ -1,8 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            $LOAD_PATH.unshift(File.expand_path('./lib', File.dirname(__FILE__)))
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'localwiki/version'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
       1 
4 
     | 
    
         
             
            Gem::Specification.new do |s|
         
     | 
| 
       2 
5 
     | 
    
         
             
              s.name        = 'localwiki_client'
         
     | 
| 
       3 
     | 
    
         
            -
              s.version     =  
     | 
| 
      
 6 
     | 
    
         
            +
              s.version     = Localwiki::VERSION
         
     | 
| 
       4 
7 
     | 
    
         
             
              s.authors     = ["Brandon Faloona", "Seth Vincent"]
         
     | 
| 
       5 
     | 
    
         
            -
              s.description = %{ A thin  
     | 
| 
      
 8 
     | 
    
         
            +
              s.description = %{ A thin client that wraps the Localwiki API. }
         
     | 
| 
       6 
9 
     | 
    
         
             
              s.summary     = "localwiki_client-#{s.version}"
         
     | 
| 
       7 
10 
     | 
    
         
             
              s.email       = 'brandon@faloona.net'
         
     | 
| 
       8 
11 
     | 
    
         
             
              s.homepage    = "http://github.com/bfaloona/localwiki_client"
         
     | 
| 
         @@ -10,7 +13,7 @@ Gem::Specification.new do |s| 
     | 
|
| 
       10 
13 
     | 
    
         
             
              s.platform    = Gem::Platform::RUBY
         
     | 
| 
       11 
14 
     | 
    
         
             
              s.required_ruby_version = '>= 1.9.2'
         
     | 
| 
       12 
15 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
              s.add_dependency(' 
     | 
| 
      
 16 
     | 
    
         
            +
              s.add_dependency('faraday')
         
     | 
| 
       14 
17 
     | 
    
         
             
              s.add_dependency('json')
         
     | 
| 
       15 
18 
     | 
    
         | 
| 
       16 
19 
     | 
    
         
             
              s.add_development_dependency('rake')
         
     | 
| 
         @@ -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
    
    
| 
         @@ -3,7 +3,7 @@ require 'localwiki_client' 
     | 
|
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            describe 'LIVE saltlakewiki.org' do
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
              subject {  
     | 
| 
      
 6 
     | 
    
         
            +
              subject { Localwiki::Client.new 'saltlakewiki.org' }
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
              context '#time_zone' do
         
     | 
| 
       9 
9 
     | 
    
         
             
                it {subject.time_zone.should eq 'America/Chicago' }
         
     | 
| 
         @@ -14,7 +14,7 @@ describe 'LIVE saltlakewiki.org' do 
     | 
|
| 
       14 
14 
     | 
    
         
             
              end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
              context '#total_resources("user")' do
         
     | 
| 
       17 
     | 
    
         
            -
                it {subject. 
     | 
| 
      
 17 
     | 
    
         
            +
                it {subject.count('user').to_i.should > 2}
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
            end
         
     | 
| 
         @@ -1,74 +1,37 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'localwiki_client'
         
     | 
| 
       3 
3 
     | 
    
         
             
            require 'rspec/mocks'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'helper'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            describe 'LocalwikiClient' do
         
     | 
| 
      
 6 
     | 
    
         
            +
            describe 'LocalwikiClient convenience class' do
         
     | 
| 
       6 
7 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
              context ' 
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
      
 8 
     | 
    
         
            +
              context 'initialize' do
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                before(:all) do
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @site_fetch_json = load_json 'site_fetch.json'
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
       9 
13 
     | 
    
         | 
| 
       10 
14 
     | 
    
         
             
                before(:each) do
         
     | 
| 
       11 
15 
     | 
    
         
             
                  response = double('response')
         
     | 
| 
       12 
     | 
    
         
            -
                  response.stub(:body) {
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                   
     | 
| 
       15 
     | 
    
         
            -
                  RestClient::Request.should_receive(:execute
         
     | 
| 
      
 16 
     | 
    
         
            +
                  response.stub(:body) { @site_fetch_json }
         
     | 
| 
      
 17 
     | 
    
         
            +
                  conn = double('conn')
         
     | 
| 
      
 18 
     | 
    
         
            +
                  Faraday.should_receive(:new
         
     | 
| 
       16 
19 
     | 
    
         
             
                    ).with(
         
     | 
| 
       17 
     | 
    
         
            -
                      {: 
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 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'}
         
     | 
| 
       20 
27 
     | 
    
         
             
                    ).and_return(response)
         
     | 
| 
       21 
28 
     | 
    
         
             
                end
         
     | 
| 
       22 
29 
     | 
    
         | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
                it {should respond_to :site_name}
         
     | 
| 
       25 
     | 
    
         
            -
                it {should respond_to :time_zone}
         
     | 
| 
       26 
     | 
    
         
            -
                it {should respond_to :language_code}
         
     | 
| 
       27 
     | 
    
         
            -
                it {should respond_to :total_resources}
         
     | 
| 
       28 
     | 
    
         
            -
                it {should respond_to :page_by_name}
         
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                context 'mockwiki.foo' do
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                  context '#time_zone' do
         
     | 
| 
       33 
     | 
    
         
            -
                    it {subject.time_zone.should eq 'America/Chicago' }
         
     | 
| 
       34 
     | 
    
         
            -
                  end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
                  context '#language_code' do
         
     | 
| 
       37 
     | 
    
         
            -
                    it {subject.language_code.should eq 'en-us'}
         
     | 
| 
       38 
     | 
    
         
            -
                  end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                  context '#total_resources("user")' do
         
     | 
| 
       41 
     | 
    
         
            -
                    it 'should eq 6' do
         
     | 
| 
       42 
     | 
    
         
            -
                      response = double('response')
         
     | 
| 
       43 
     | 
    
         
            -
                      response.stub(:body) {
         
     | 
| 
       44 
     | 
    
         
            -
                        %q<{"meta": {"limit": 0, "offset": 0, "total_count": 6}, "objects": [{"date_joined": "2012-10-05T21:12:34.103559", "first_name": "", "last_name": "", "resource_uri": "", "username": "AnonymousUser"}, {"date_joined": "2012-11-02T15:24:44.621040", "first_name": "Kris", "last_name": "Trujillo", "resource_uri": "/api/user/3", "username": "kristrujillo"}, {"date_joined": "2012-10-17T14:01:40.778496", "first_name": "Tod", "last_name": "Robbins", "resource_uri": "/api/user/2", "username": "todrobbins"}, {"date_joined": "2012-11-20T21:47:33.152069", "first_name": "Jessie", "last_name": "", "resource_uri": "/api/user/4", "username": "jessiepech"}, {"date_joined": "2012-10-05T21:12:33", "first_name": "Andrew", "last_name": "Sullivan", "resource_uri": "/api/user/1", "username": "licyeus"}, {"date_joined": "2012-12-08T15:33:29.251275", "first_name": "Ryan", "last_name": "", "resource_uri": "/api/user/5", "username": "saltlakeryan"}]}>
         
     | 
| 
       45 
     | 
    
         
            -
                      }
         
     | 
| 
       46 
     | 
    
         
            -
                      RestClient::Request.should_receive(:execute
         
     | 
| 
       47 
     | 
    
         
            -
                        ).with(
         
     | 
| 
       48 
     | 
    
         
            -
                            {:method => :get,
         
     | 
| 
       49 
     | 
    
         
            -
                             :url => 'http://mockwiki.foo/api/user?limit=1&format=json',
         
     | 
| 
       50 
     | 
    
         
            -
                             :timeout => 120}
         
     | 
| 
       51 
     | 
    
         
            -
                        ).and_return(response)
         
     | 
| 
       52 
     | 
    
         
            -
                      subject.total_resources('user').should eq 6
         
     | 
| 
       53 
     | 
    
         
            -
                    end
         
     | 
| 
       54 
     | 
    
         
            -
                  end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                  context "#page_by_name('Luna Park Cafe')" do
         
     | 
| 
       57 
     | 
    
         
            -
                    it 'has content matching "amusement park"' do
         
     | 
| 
       58 
     | 
    
         
            -
                      response = double('response')
         
     | 
| 
       59 
     | 
    
         
            -
                      response.stub(:body) {
         
     | 
| 
       60 
     | 
    
         
            -
                        %q[{"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", "id": 572, "map": "/api/map/Luna_Park_Cafe", "name": "Luna Park Cafe", "page_tags": "/api/page_tags/Luna_Park_Cafe", "resource_uri": "/api/page/Luna_Park_Cafe", "slug": "luna park cafe"}]
         
     | 
| 
       61 
     | 
    
         
            -
                      }
         
     | 
| 
       62 
     | 
    
         
            -
                      RestClient::Request.should_receive(:execute
         
     | 
| 
       63 
     | 
    
         
            -
                        ).with(
         
     | 
| 
       64 
     | 
    
         
            -
                          {:method => :get,
         
     | 
| 
       65 
     | 
    
         
            -
                           :url => 'http://mockwiki.foo/api/page/Luna_Park_Cafe?limit=0&format=json',
         
     | 
| 
       66 
     | 
    
         
            -
                           :timeout => 120}
         
     | 
| 
       67 
     | 
    
         
            -
                        ).and_return(response)
         
     | 
| 
       68 
     | 
    
         
            -
                      subject.page_by_name('Luna Park Cafe')['content'].should match(/amusement park/)
         
     | 
| 
       69 
     | 
    
         
            -
                    end
         
     | 
| 
       70 
     | 
    
         
            -
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
                subject { LocalwikiClient.new 'mockwiki.foo' }
         
     | 
| 
       71 
31 
     | 
    
         | 
| 
      
 32 
     | 
    
         
            +
                context '#site_name' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  it { subject.site_name.should eq 'Salt Lake Wiki' }
         
     | 
| 
       72 
34 
     | 
    
         
             
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
       73 
36 
     | 
    
         
             
              end
         
     | 
| 
       74 
37 
     | 
    
         
             
            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
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: localwiki_client
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
       5 
5 
     | 
    
         
             
              prerelease: 
         
     | 
| 
       6 
6 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       7 
7 
     | 
    
         
             
            authors:
         
     | 
| 
         @@ -10,10 +10,10 @@ authors: 
     | 
|
| 
       10 
10 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       11 
11 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       12 
12 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       13 
     | 
    
         
            -
            date: 2013- 
     | 
| 
      
 13 
     | 
    
         
            +
            date: 2013-02-14 00:00:00.000000000 Z
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies:
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       16 
     | 
    
         
            -
              name:  
     | 
| 
      
 16 
     | 
    
         
            +
              name: faraday
         
     | 
| 
       17 
17 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
       18 
18 
     | 
    
         
             
                none: false
         
     | 
| 
       19 
19 
     | 
    
         
             
                requirements:
         
     | 
| 
         @@ -156,7 +156,7 @@ dependencies: 
     | 
|
| 
       156 
156 
     | 
    
         
             
                - - ! '>='
         
     | 
| 
       157 
157 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       158 
158 
     | 
    
         
             
                    version: '0'
         
     | 
| 
       159 
     | 
    
         
            -
            description: ! ' A thin  
     | 
| 
      
 159 
     | 
    
         
            +
            description: ! ' A thin client that wraps the Localwiki API. '
         
     | 
| 
       160 
160 
     | 
    
         
             
            email: brandon@faloona.net
         
     | 
| 
       161 
161 
     | 
    
         
             
            executables: []
         
     | 
| 
       162 
162 
     | 
    
         
             
            extensions: []
         
     | 
| 
         @@ -170,15 +170,25 @@ files: 
     | 
|
| 
       170 
170 
     | 
    
         
             
            - History.txt
         
     | 
| 
       171 
171 
     | 
    
         
             
            - README.md
         
     | 
| 
       172 
172 
     | 
    
         
             
            - Rakefile
         
     | 
| 
      
 173 
     | 
    
         
            +
            - lib/localwiki/client.rb
         
     | 
| 
      
 174 
     | 
    
         
            +
            - lib/localwiki/version.rb
         
     | 
| 
       173 
175 
     | 
    
         
             
            - lib/localwiki_client.rb
         
     | 
| 
       174 
     | 
    
         
            -
            -  
     | 
| 
      
 176 
     | 
    
         
            +
            - localwiki_client-0.0.4.gem
         
     | 
| 
       175 
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
         
     | 
| 
       176 
183 
     | 
    
         
             
            - spec/integration/live_saltlake_wiki_spec.rb
         
     | 
| 
       177 
184 
     | 
    
         
             
            - spec/localwiki_client_spec.rb
         
     | 
| 
      
 185 
     | 
    
         
            +
            - spec/page_spec.rb
         
     | 
| 
      
 186 
     | 
    
         
            +
            - spec/site_spec.rb
         
     | 
| 
      
 187 
     | 
    
         
            +
            - spec/user_spec.rb
         
     | 
| 
       178 
188 
     | 
    
         
             
            homepage: http://github.com/bfaloona/localwiki_client
         
     | 
| 
       179 
189 
     | 
    
         
             
            licenses:
         
     | 
| 
       180 
190 
     | 
    
         
             
            - MIT
         
     | 
| 
       181 
     | 
    
         
            -
            post_install_message: ! "\n    Thank you for installing localwiki_client 0.0 
     | 
| 
      
 191 
     | 
    
         
            +
            post_install_message: ! "\n    Thank you for installing localwiki_client 0.1.0\n  "
         
     | 
| 
       182 
192 
     | 
    
         
             
            rdoc_options:
         
     | 
| 
       183 
193 
     | 
    
         
             
            - --charset=UTF-8
         
     | 
| 
       184 
194 
     | 
    
         
             
            require_paths:
         
     | 
| 
         @@ -200,6 +210,6 @@ rubyforge_project: 
     | 
|
| 
       200 
210 
     | 
    
         
             
            rubygems_version: 1.8.24
         
     | 
| 
       201 
211 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       202 
212 
     | 
    
         
             
            specification_version: 3
         
     | 
| 
       203 
     | 
    
         
            -
            summary: localwiki_client-0.0 
     | 
| 
      
 213 
     | 
    
         
            +
            summary: localwiki_client-0.1.0
         
     | 
| 
       204 
214 
     | 
    
         
             
            test_files: []
         
     | 
| 
       205 
215 
     | 
    
         
             
            has_rdoc: 
         
     | 
| 
         @@ -1,70 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'rest-client'
         
     | 
| 
       2 
     | 
    
         
            -
            require 'json/pure'
         
     | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
       4 
     | 
    
         
            -
            ##
         
     | 
| 
       5 
     | 
    
         
            -
            # A client that wraps the localwiki api for a given server instance
         
     | 
| 
       6 
     | 
    
         
            -
            #
         
     | 
| 
       7 
     | 
    
         
            -
            class LocalwikiClient
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              attr_accessor :hostname       # hostname of the server we'd like to point at
         
     | 
| 
       10 
     | 
    
         
            -
              attr_reader   :site_name      # site resource - display name of wiki
         
     | 
| 
       11 
     | 
    
         
            -
              attr_reader   :time_zone      # site resource - time zone of server, e.g. 'America/Chicago'
         
     | 
| 
       12 
     | 
    
         
            -
              attr_reader   :language_code  # site resource - language code of the server, e.g. 'en-us'
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
              ##
         
     | 
| 
       15 
     | 
    
         
            -
              # Creating a LocalWikiClient instance will get it's site resource data
         
     | 
| 
       16 
     | 
    
         
            -
              #
         
     | 
| 
       17 
     | 
    
         
            -
              #   LocalwikiClient.new 'seattlewiki.net'
         
     | 
| 
       18 
     | 
    
         
            -
              #
         
     | 
| 
       19 
     | 
    
         
            -
              def initialize hostname
         
     | 
| 
       20 
     | 
    
         
            -
                @hostname = hostname
         
     | 
| 
       21 
     | 
    
         
            -
                collect_site_details
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              ##
         
     | 
| 
       25 
     | 
    
         
            -
              # Get site resource and set ivars
         
     | 
| 
       26 
     | 
    
         
            -
              #
         
     | 
| 
       27 
     | 
    
         
            -
              def collect_site_details
         
     | 
| 
       28 
     | 
    
         
            -
                site = get_resource('site/1')
         
     | 
| 
       29 
     | 
    
         
            -
                @site_name = site['name']
         
     | 
| 
       30 
     | 
    
         
            -
                @time_zone = site['time_zone']
         
     | 
| 
       31 
     | 
    
         
            -
                @language_code = site['language_code']
         
     | 
| 
       32 
     | 
    
         
            -
              end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
              ##
         
     | 
| 
       35 
     | 
    
         
            -
              # http get request
         
     | 
| 
       36 
     | 
    
         
            -
              # url is formatted as http://[url-to-wiki]/[thing-you-want]&format=json
         
     | 
| 
       37 
     | 
    
         
            -
              #
         
     | 
| 
       38 
     | 
    
         
            -
              def get(resource,timeout=120)
         
     | 
| 
       39 
     | 
    
         
            -
                response = RestClient::Request.execute(
         
     | 
| 
       40 
     | 
    
         
            -
                    :method => :get,
         
     | 
| 
       41 
     | 
    
         
            -
                    :url => 'http://' + @hostname + resource + '&format=json',
         
     | 
| 
       42 
     | 
    
         
            -
                    :timeout => timeout)
         
     | 
| 
       43 
     | 
    
         
            -
                JSON.parse(response.body)
         
     | 
| 
       44 
     | 
    
         
            -
              end
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
              ##
         
     | 
| 
       47 
     | 
    
         
            -
              # http get of a specfic type of resource
         
     | 
| 
       48 
     | 
    
         
            -
              # resource_types are "site", "page", "user", "file", "map"
         
     | 
| 
       49 
     | 
    
         
            -
              # limit is an integer
         
     | 
| 
       50 
     | 
    
         
            -
              # filters is a querystring param in the form "&option=value"
         
     | 
| 
       51 
     | 
    
         
            -
              def get_resource(content_type,limit=0,filters='')
         
     | 
| 
       52 
     | 
    
         
            -
                resource = '/api/' + content_type + '?limit=' + limit.to_s + filters
         
     | 
| 
       53 
     | 
    
         
            -
                get(resource)
         
     | 
| 
       54 
     | 
    
         
            -
              end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
              ##
         
     | 
| 
       57 
     | 
    
         
            -
              # Request total_count of given resource
         
     | 
| 
       58 
     | 
    
         
            -
              #
         
     | 
| 
       59 
     | 
    
         
            -
              def total_resources(content_type)
         
     | 
| 
       60 
     | 
    
         
            -
                get_resource(content_type,1)["meta"]["total_count"]
         
     | 
| 
       61 
     | 
    
         
            -
              end
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
              ##
         
     | 
| 
       64 
     | 
    
         
            -
              # Return a page that matches name ("The Page Name" or "The_Page_Name")
         
     | 
| 
       65 
     | 
    
         
            -
              #
         
     | 
| 
       66 
     | 
    
         
            -
              def page_by_name(name)
         
     | 
| 
       67 
     | 
    
         
            -
                get_resource("page/#{name.gsub!(/\s/, '_')}")
         
     | 
| 
       68 
     | 
    
         
            -
              end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
            end
         
     |