tinysou 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a74554800e9ac88933c3a6852eb52e1b5d7ff9fb
4
+ data.tar.gz: edb93ce61fdeecb128d08259783277f07358d534
5
+ SHA512:
6
+ metadata.gz: 4042b977fd3aa1c490c6e98bb66cd09e447b8b917a9d6ac690b0e740ba3080583c97d2b01a98621302428b36340abef37102aae33ef34200dace2901eb5bc9aa
7
+ data.tar.gz: 6db4c1b4edbedf376eade3b1d18608145af09b8013ff5c45fa37c5c2d89561a9b7089bbd9e0656b35f21df8dd800c67efd4070c856f86cd57551a8f6bb37da38
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - 2.1.0
7
+ - jruby
8
+ before_install:
9
+ - gem update bundler
10
+ - bundle --version
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tinysou.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tinysou (0.0.1)
5
+ faraday
6
+ multi_json
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.6)
12
+ crack (0.4.2)
13
+ safe_yaml (~> 1.0.0)
14
+ diff-lcs (1.2.5)
15
+ faraday (0.9.0)
16
+ multipart-post (>= 1.2, < 3)
17
+ multi_json (1.10.1)
18
+ multipart-post (2.0.0)
19
+ rake (10.3.2)
20
+ rspec (3.1.0)
21
+ rspec-core (~> 3.1.0)
22
+ rspec-expectations (~> 3.1.0)
23
+ rspec-mocks (~> 3.1.0)
24
+ rspec-core (3.1.3)
25
+ rspec-support (~> 3.1.0)
26
+ rspec-expectations (3.1.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.1.0)
29
+ rspec-mocks (3.1.0)
30
+ rspec-support (~> 3.1.0)
31
+ rspec-support (3.1.0)
32
+ safe_yaml (1.0.3)
33
+ webmock (1.18.0)
34
+ addressable (>= 2.3.6)
35
+ crack (>= 0.3.2)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 1.0)
42
+ rake
43
+ rspec (>= 3.0)
44
+ tinysou!
45
+ webmock
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 微搜索
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # Tinysou
2
+
3
+ [![Build Status](https://travis-ci.org/tinysou/tinysou-ruby.svg?branch=master)](https://travis-ci.org/tinysou/tinysou-ruby)
4
+
5
+ Ruby library for the Tinysou API.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'tinysou'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install tinysou
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ client = Tinysou::Client.new 'YOUR_TOKEN'
27
+ ```
28
+
29
+ ### Engine
30
+
31
+ List:
32
+
33
+ ```ruby
34
+ client.engines
35
+ ```
36
+
37
+ Create:
38
+
39
+ ```ruby
40
+ client.create_engine name: 'blog', display_name: 'Blog'
41
+ ```
42
+
43
+ Read:
44
+
45
+ ```ruby
46
+ client.engine 'blog'
47
+ ```
48
+
49
+ Update:
50
+
51
+ ```ruby
52
+ client.update_engine 'blog', display_name: 'My Blog'
53
+ ```
54
+
55
+ Delete:
56
+
57
+ ```ruby
58
+ client.destroy_engine 'blog'
59
+ ```
60
+
61
+ ### Collection
62
+
63
+ List:
64
+
65
+ ```ruby
66
+ client.collections 'blog'
67
+ ```
68
+
69
+ Create:
70
+
71
+ ```ruby
72
+ client.create_collection 'blog', name: 'posts', field_types: {
73
+ title: 'string',
74
+ tags: 'string',
75
+ author: 'enum',
76
+ date: 'date',
77
+ body: 'text'
78
+ }
79
+ ```
80
+
81
+ Read:
82
+
83
+ ```ruby
84
+ client.collection 'blog', 'posts'
85
+ ```
86
+
87
+ Destroy:
88
+
89
+ ```ruby
90
+ client.destroy_collection 'blog', 'posts'
91
+ ```
92
+
93
+ ### Document
94
+
95
+ List:
96
+
97
+ ```ruby
98
+ client.documents 'blog', 'posts', page: 0, per_page: 20
99
+ ```
100
+
101
+ Create:
102
+
103
+ ```ruby
104
+ client.create_document 'blog', 'posts', {
105
+ title: 'My First Post',
106
+ tags: ['news'],
107
+ author: 'Author',
108
+ date: '2014-08-16T00:00:00Z',
109
+ body: 'Tinysou start online today!'
110
+ }
111
+ ```
112
+
113
+ Read:
114
+
115
+ ```ruby
116
+ client.document 'blog', 'posts', '293ddf9205df9b36ba5761d61ca59a29'
117
+ ```
118
+
119
+ Update:
120
+
121
+ ```ruby
122
+ client.update_document 'blog', 'posts', '293ddf9205df9b36ba5761d61ca59a29', {
123
+ title: 'First Post'
124
+ }
125
+ ```
126
+
127
+ Delete:
128
+
129
+ ```ruby
130
+ client.destroy_document 'blog', 'posts', '293ddf9205df9b36ba5761d61ca59a29'
131
+ ```
132
+
133
+ ### Search
134
+
135
+ ```ruby
136
+ client.search 'blog', q: 'tinysou', c: 'posts'
137
+ ```
138
+
139
+ ### Autocomplete
140
+
141
+ ```ruby
142
+ client.autocomplete 'blog', q: 't', c: 'posts'
143
+ ```
144
+
145
+ ## Contributing
146
+
147
+ 1. Fork it ( https://github.com/[my-github-username]/tinysou/fork )
148
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
149
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
150
+ 4. Push to the branch (`git push origin my-new-feature`)
151
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task test: :spec
7
+ task default: :spec
8
+ rescue LoadError
9
+ end
data/examples/demo.rb ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+ require 'tinysou'
3
+
4
+ TOKEN = 'YOUR_TOKEN'
5
+ ENGINE = 'YOUR_ENGINE_NAME'
6
+
7
+ engine = {
8
+ name: ENGINE,
9
+ display_name: 'My Blog'
10
+ }
11
+
12
+ collection = {
13
+ name: 'posts',
14
+ field_types: {
15
+ title: 'string',
16
+ tags: 'string',
17
+ author: 'enum',
18
+ date: 'date',
19
+ body: 'text'
20
+ }
21
+ }
22
+
23
+ document = {
24
+ title: 'My First Post',
25
+ tags: ['news'],
26
+ author: 'Author',
27
+ date: Time.now,
28
+ body: 'Tinysou start online today!'
29
+ }
30
+
31
+ client = Tinysou::Client.new TOKEN
32
+
33
+ tasks = {
34
+ engines: -> { client.engines },
35
+ create_engine: -> { client.create_engine engine },
36
+ engine: -> { client.engine engine[:name] },
37
+ update_engine: -> { client.update_engine engine[:name], engine },
38
+ destroy_engine: -> { client.destroy_engine engine[:name] },
39
+ collections: -> { client.collections engine[:name] },
40
+ create_collection: -> { client.create_collection engine[:name], collection },
41
+ collection: -> { client.collection engine[:name], collection[:name] },
42
+ destroy_collection: -> { client.destroy_collection engine[:name], collection[:name] },
43
+ documents: -> { client.documents engine[:name], collection[:name], page: 0, per_page: 20 },
44
+ create_document: -> { client.create_document engine[:name], collection[:name], document },
45
+ update_document: lambda do
46
+ id = client.documents(engine[:name], collection[:name]).first[:id]
47
+ client.update_document engine[:name], collection[:name], id, document
48
+ end,
49
+ destroy_document: lambda do
50
+ id = client.documents(engine[:name], collection[:name]).first[:id]
51
+ client.destroy_document engine[:name], collection[:name], id
52
+ end,
53
+ search: -> { client.search engine[:name], q: 'first', c: collection[:name] },
54
+ autocomplete: -> { client.autocomplete engine[:name], q: 'fi', c: collection[:name] }
55
+ }
56
+
57
+ if ARGV[0]
58
+ arg = ARGV[0].to_sym
59
+ p tasks[arg].call if tasks.include? arg
60
+ else
61
+ puts 'Available arguments:'
62
+ tasks.each { |k, _| puts k.to_s }
63
+ end
data/lib/tinysou.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'multi_json'
2
+ require 'faraday'
3
+
4
+ require 'tinysou/client'
5
+ require 'tinysou/version'
6
+
7
+ # Ruby client for the Tinysou API
8
+ module Tinysou
9
+ end
@@ -0,0 +1,64 @@
1
+ require 'tinysou/version'
2
+ require 'tinysou/client/engines'
3
+ require 'tinysou/client/collections'
4
+ require 'tinysou/client/documents'
5
+ require 'tinysou/client/search'
6
+
7
+ module Tinysou
8
+ # Client for the Tinysou API
9
+ class Client
10
+ include Tinysou::Client::Engines
11
+ include Tinysou::Client::Collections
12
+ include Tinysou::Client::Documents
13
+ include Tinysou::Client::Search
14
+
15
+ attr_accessor :token
16
+
17
+ def initialize(token)
18
+ @token = token
19
+ @conn = Faraday.new(url: 'http://api.tinysou.com/v1/') do |faraday|
20
+ faraday.adapter Faraday.default_adapter
21
+ end
22
+ @headers = { 'Content-type' => 'application/json',
23
+ 'Authorization' => "token #{@token}",
24
+ 'User-Agent' => "Tinysou-Ruby/#{Tinysou::VERSION}" }
25
+ end
26
+
27
+ def get(path, params = nil)
28
+ request :get, path, params, nil
29
+ end
30
+
31
+ def post(path, data = nil)
32
+ request :post, path, nil, data
33
+ end
34
+
35
+ def put(path, data = nil)
36
+ request :put, path, nil, data
37
+ end
38
+
39
+ def delete(path, params = nil)
40
+ request :delete, path, params, nil
41
+ end
42
+
43
+ private
44
+
45
+ def request(method, path, params, data)
46
+ res = @conn.run_request(method,
47
+ path,
48
+ MultiJson.dump(data),
49
+ @headers) do |req|
50
+ req.params.update(params) if params
51
+ yield(req) if block_given?
52
+ end
53
+ if res.status == 204
54
+ true
55
+ elsif res.status > 400
56
+ fail res.body
57
+ elsif !(res.body.nil? || res.body.empty?)
58
+ MultiJson.load(res.body, symbolize_keys: true)
59
+ else
60
+ nil
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,26 @@
1
+ module Tinysou
2
+ class Client
3
+ # Methods for the Collections API
4
+ module Collections
5
+ def collections(engine, params = {})
6
+ get "engines/#{engine}/collections", params
7
+ end
8
+
9
+ def create_collection(engine, attrs = {})
10
+ post "engines/#{engine}/collections", attrs
11
+ end
12
+
13
+ def collection(engine, name)
14
+ get "engines/#{engine}/collections/#{name}"
15
+ end
16
+
17
+ def update_collection(engine, name, attrs = {})
18
+ put "engines/#{engine}/collections/#{name}", attrs
19
+ end
20
+
21
+ def destroy_collection(engine, name)
22
+ delete "engines/#{engine}/collections/#{name}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Tinysou
2
+ class Client
3
+ # Methods for the Documents API
4
+ module Documents
5
+ def documents(engine, collection, params = {})
6
+ get "engines/#{engine}/collections/#{collection}/documents", params
7
+ end
8
+
9
+ def create_document(engine, collection, attrs = {})
10
+ post "engines/#{engine}/collections/#{collection}/documents", attrs
11
+ end
12
+
13
+ def document(engine, collection, id)
14
+ get "engines/#{engine}/collections/#{collection}/documents/#{id}"
15
+ end
16
+
17
+ def update_document(engine, collection, id, attrs = {})
18
+ put "engines/#{engine}/collections/#{collection}/documents/#{id}", attrs
19
+ end
20
+
21
+ def destroy_document(engine, collection, id)
22
+ delete "engines/#{engine}/collections/#{collection}/documents/#{id}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module Tinysou
2
+ class Client
3
+ # Methods for the Engines API
4
+ module Engines
5
+ def engines(params = {})
6
+ get 'engines', params
7
+ end
8
+
9
+ def create_engine(attrs = {})
10
+ post 'engines', attrs
11
+ end
12
+
13
+ def engine(name)
14
+ get "engines/#{name}"
15
+ end
16
+
17
+ def update_engine(name, attrs = {})
18
+ put "engines/#{name}", attrs
19
+ end
20
+
21
+ def destroy_engine(name)
22
+ delete "engines/#{name}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ module Tinysou
2
+ class Client
3
+ # Methods for the Search API
4
+ module Search
5
+ def search(engine, params = {})
6
+ post "engines/#{engine}/search", params
7
+ end
8
+
9
+ def autocomplete(engine, params = {})
10
+ post "engines/#{engine}/autocomplete", params
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ module Tinysou
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "posts",
3
+ "field_types": {
4
+ "title": "string",
5
+ "tags": "string",
6
+ "author": "enum",
7
+ "date": "enum",
8
+ "body": "text"
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ [{
2
+ "name": "posts",
3
+ "field_types": {
4
+ "title": "string",
5
+ "tags": "string",
6
+ "author": "enum",
7
+ "date": "enum",
8
+ "body": "text"
9
+ }
10
+ }]
@@ -0,0 +1,7 @@
1
+ {
2
+ "title": "My First Post",
3
+ "tags": ["news"],
4
+ "author": "Author",
5
+ "date": "2014-08-16T00:00:00Z",
6
+ "body": "Tinysou start online today!"
7
+ }
@@ -0,0 +1,8 @@
1
+ [{
2
+ "id": "1",
3
+ "title": "My First Post",
4
+ "tags": ["news"],
5
+ "author": "Author",
6
+ "date": "2014-08-16T00:00:00Z",
7
+ "body": "Tinysou start online today!"
8
+ }]
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "blog",
3
+ "display_name": "Blog"
4
+ }
@@ -0,0 +1,4 @@
1
+ [{
2
+ "name": "blog",
3
+ "display_name": "Blog"
4
+ }]
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": "1"
3
+ }
data/spec/helper.rb ADDED
@@ -0,0 +1,36 @@
1
+ def tinysou_url(path)
2
+ "http://api.tinysou.com/v1/#{path}"
3
+ end
4
+
5
+ def stub_get(path)
6
+ stub_request(:get, tinysou_url(path))
7
+ end
8
+
9
+ def stub_post(path)
10
+ stub_request(:post, tinysou_url(path))
11
+ end
12
+
13
+ def stub_put(path)
14
+ stub_request(:put, tinysou_url(path))
15
+ end
16
+
17
+ def stub_delete(path)
18
+ stub_request(:delete, tinysou_url(path))
19
+ end
20
+
21
+ def fixture_path
22
+ File.expand_path('../fixtures', __FILE__)
23
+ end
24
+
25
+ def fixture(file)
26
+ File.new(fixture_path + '/' + file)
27
+ end
28
+
29
+ def json_response(file)
30
+ {
31
+ body: fixture(file),
32
+ headers: {
33
+ content_type: 'application/json'
34
+ }
35
+ }
36
+ end
@@ -0,0 +1,95 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+
18
+ require 'tinysou'
19
+ require 'webmock/rspec'
20
+ require 'helper'
21
+
22
+ RSpec.configure do |config|
23
+ # rspec-expectations config goes here. You can use an alternate
24
+ # assertion/expectation library such as wrong or the stdlib/minitest
25
+ # assertions if you prefer.
26
+ config.expect_with :rspec do |expectations|
27
+ # This option will default to `true` in RSpec 4. It makes the `description`
28
+ # and `failure_message` of custom matchers include text for helper methods
29
+ # defined using `chain`, e.g.:
30
+ # be_bigger_than(2).and_smaller_than(4).description
31
+ # # => "be bigger than 2 and smaller than 4"
32
+ # ...rather than:
33
+ # # => "be bigger than 2"
34
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
+ end
36
+
37
+ # rspec-mocks config goes here. You can use an alternate test double
38
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
39
+ config.mock_with :rspec do |mocks|
40
+ # Prevents you from mocking or stubbing a method that does not exist on
41
+ # a real object. This is generally recommended, and will default to
42
+ # `true` in RSpec 4.
43
+ mocks.verify_partial_doubles = true
44
+ end
45
+
46
+
47
+ # The settings below are suggested to provide a good initial experience
48
+ # with RSpec, but feel free to customize to your heart's content.
49
+
50
+ # These two settings work together to allow you to limit a spec run
51
+ # to individual examples or groups you care about by tagging them with
52
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
+ # get run.
54
+ # config.filter_run :focus
55
+ # config.run_all_when_everything_filtered = true
56
+
57
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
58
+ # For more details, see:
59
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
60
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
61
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
62
+ # config.disable_monkey_patching!
63
+
64
+ # This setting enables warnings. It's recommended, but in some cases may
65
+ # be too noisy due to issues in dependencies.
66
+ # config.warnings = true
67
+
68
+ # Many RSpec users commonly either run the entire suite or an individual
69
+ # file, and it's useful to allow more verbose output when running an
70
+ # individual spec file.
71
+ # if config.files_to_run.one?
72
+ # Use the documentation formatter for detailed output,
73
+ # unless a formatter has already been configured
74
+ # (e.g. via a command-line flag).
75
+ # config.default_formatter = 'doc'
76
+ # end
77
+
78
+ # Print the 10 slowest examples and example groups at the
79
+ # end of the spec run, to help surface which specs are running
80
+ # particularly slow.
81
+ # config.profile_examples = 10
82
+
83
+ # Run specs in random order to surface order dependencies. If you find an
84
+ # order dependency and want to debug it, you can fix the order by providing
85
+ # the seed, which is printed after each run.
86
+ # --seed 1234
87
+ config.order = :random
88
+
89
+ # Seed global randomization in this process using the `--seed` CLI option.
90
+ # Setting this allows you to use `--seed` to deterministically reproduce
91
+ # test failures related to randomization by passing the same `--seed` value
92
+ # as the one that triggered the failure.
93
+ # Kernel.srand config.seed
94
+
95
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinysou::Client::Collections do
4
+
5
+ let(:client) { Tinysou::Client.new 'token' }
6
+
7
+ describe '.collections' do
8
+ it 'lists collections' do
9
+ request = stub_get('engines/blog/collections')
10
+ .to_return(json_response('collections.json'))
11
+ client.collections 'blog'
12
+ assert_requested request
13
+ end
14
+ end
15
+
16
+ describe '.create_collection' do
17
+ it 'creates an collection' do
18
+ request = stub_post('engines/blog/collections')
19
+ .to_return(json_response('collection.json'))
20
+ client.create_collection 'blog', name: 'posts'
21
+ assert_requested request
22
+ end
23
+ end
24
+
25
+ describe '.collection' do
26
+ it 'read an collection' do
27
+ request = stub_get('engines/blog/collections/posts')
28
+ .to_return(json_response('collection.json'))
29
+ client.collection 'blog', 'posts'
30
+ assert_requested request
31
+ end
32
+ end
33
+
34
+ describe '.destroy_collection' do
35
+ it 'destroys an collection' do
36
+ request = stub_delete('engines/blog/collections/posts')
37
+ .to_return(status: 204)
38
+ client.destroy_collection 'blog', 'posts'
39
+ assert_requested request
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinysou::Client::Documents do
4
+
5
+ let(:client) { Tinysou::Client.new 'token' }
6
+
7
+ describe '.documents' do
8
+ it 'lists documents' do
9
+ request = stub_get('engines/blog/collections/posts/documents')
10
+ .to_return(json_response('documents.json'))
11
+ client.documents 'blog', 'posts'
12
+ assert_requested request
13
+ end
14
+ end
15
+
16
+ describe '.create_document' do
17
+ it 'creates an document' do
18
+ request = stub_post('engines/blog/collections/posts/documents')
19
+ .to_return(json_response('document.json'))
20
+ client.create_document 'blog', 'posts', title: 'My First Blog'
21
+ assert_requested request
22
+ end
23
+ end
24
+
25
+ describe '.document' do
26
+ it 'read an document' do
27
+ request = stub_get('engines/blog/collections/posts/documents/1')
28
+ .to_return(json_response('document.json'))
29
+ client.document 'blog', 'posts', '1'
30
+ assert_requested request
31
+ end
32
+ end
33
+
34
+ describe '.update_document' do
35
+ it 'updates an document' do
36
+ request = stub_put('engines/blog/collections/posts/documents/1')
37
+ .to_return(json_response('document.json'))
38
+ client.update_document 'blog', 'posts', '1', title: 'First Blog'
39
+ assert_requested request
40
+ end
41
+ end
42
+
43
+ describe '.destroy_document' do
44
+ it 'destroys an document' do
45
+ request = stub_delete('engines/blog/collections/posts/documents/1')
46
+ .to_return(status: 204)
47
+ client.destroy_document 'blog', 'posts', '1'
48
+ assert_requested request
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinysou::Client::Engines do
4
+
5
+ let(:client) { Tinysou::Client.new 'token' }
6
+
7
+ describe '.engines' do
8
+ it 'lists engines' do
9
+ request = stub_get('engines').to_return(json_response('engines.json'))
10
+ client.engines
11
+ assert_requested request
12
+ end
13
+ end
14
+
15
+ describe '.create_engine' do
16
+ it 'creates an engine' do
17
+ request = stub_post('engines').to_return(json_response('engine.json'))
18
+ client.create_engine name: 'blog', display_name: 'Blog'
19
+ assert_requested request
20
+ end
21
+ end
22
+
23
+ describe '.engine' do
24
+ it 'read an engine' do
25
+ request = stub_get('engines/blog').to_return(json_response('engine.json'))
26
+ client.engine 'blog'
27
+ assert_requested request
28
+ end
29
+ end
30
+
31
+ describe '.update_engine' do
32
+ it 'updates an engine' do
33
+ request = stub_put('engines/blog').to_return(json_response('engine.json'))
34
+ client.update_engine 'blog', display_name: 'MyBlog'
35
+ assert_requested request
36
+ end
37
+ end
38
+
39
+ describe '.destroy_engine' do
40
+ it 'destroys an engine' do
41
+ request = stub_delete('engines/blog').to_return(status: 204)
42
+ client.destroy_engine('blog')
43
+ assert_requested request
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinysou::Client::Search do
4
+
5
+ let(:client) { Tinysou::Client.new 'token' }
6
+
7
+ describe '.search' do
8
+ it 'search' do
9
+ request = stub_post('engines/blog/search')
10
+ client.search('blog', q: 'tinysou', c: 'page')
11
+ assert_requested request
12
+ end
13
+ end
14
+
15
+ describe '.autocomplete' do
16
+ it 'autocomplete' do
17
+ request = stub_post('engines/blog/autocomplete')
18
+ client.autocomplete('blog', q: 'ti', c: 'page')
19
+ assert_requested request
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ describe Tinysou::Client do
4
+
5
+ let(:client) { Tinysou::Client.new 'token' }
6
+
7
+ it 'init' do
8
+ c = Tinysou::Client.new 'token'
9
+ expect(c.token).to eq('token')
10
+ end
11
+
12
+ describe '.get' do
13
+ it 'makes a GET request' do
14
+ request = stub_get('').to_return(json_response('version.json'))
15
+ client.get ''
16
+ assert_requested request
17
+ end
18
+ end
19
+
20
+ describe '.post' do
21
+ it 'makes a POST request' do
22
+ request = stub_post('').to_return(json_response('version.json'))
23
+ client.post ''
24
+ assert_requested request
25
+ end
26
+ end
27
+
28
+ describe '.put' do
29
+ it 'makes a PUT request' do
30
+ request = stub_put('').to_return(json_response('version.json'))
31
+ client.put ''
32
+ assert_requested request
33
+ end
34
+ end
35
+
36
+ describe '.delete' do
37
+ it 'makes a DELETE request' do
38
+ request = stub_delete('').to_return(status: 204)
39
+ client.delete ''
40
+ assert_requested request
41
+ end
42
+ end
43
+ end
data/tinysou.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tinysou/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tinysou'
8
+ spec.version = Tinysou::VERSION
9
+ spec.authors = ['Hemslo Wang']
10
+ spec.email = ['hemslo.wang@gmail.com']
11
+ spec.summary = %q(Tinysou Ruby client)
12
+ spec.description = %q(Tinysou Ruby client)
13
+ spec.homepage = 'https://github.com/tinysou/tinysou-ruby'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+
22
+ spec.add_dependency 'multi_json'
23
+ spec.add_dependency 'faraday'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.0'
26
+ spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '>= 3.0'
28
+ spec.add_development_dependency 'webmock'
29
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tinysou
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Hemslo Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: multi_json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Tinysou Ruby client
98
+ email:
99
+ - hemslo.wang@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE
110
+ - README.md
111
+ - Rakefile
112
+ - examples/demo.rb
113
+ - lib/tinysou.rb
114
+ - lib/tinysou/client.rb
115
+ - lib/tinysou/client/collections.rb
116
+ - lib/tinysou/client/documents.rb
117
+ - lib/tinysou/client/engines.rb
118
+ - lib/tinysou/client/search.rb
119
+ - lib/tinysou/version.rb
120
+ - spec/fixtures/collection.json
121
+ - spec/fixtures/collections.json
122
+ - spec/fixtures/document.json
123
+ - spec/fixtures/documents.json
124
+ - spec/fixtures/engine.json
125
+ - spec/fixtures/engines.json
126
+ - spec/fixtures/version.json
127
+ - spec/helper.rb
128
+ - spec/spec_helper.rb
129
+ - spec/tinysou/client/collections_spec.rb
130
+ - spec/tinysou/client/documents_spec.rb
131
+ - spec/tinysou/client/engines_spec.rb
132
+ - spec/tinysou/client/search_spec.rb
133
+ - spec/tinysou/client_spec.rb
134
+ - tinysou.gemspec
135
+ homepage: https://github.com/tinysou/tinysou-ruby
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.2.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Tinysou Ruby client
159
+ test_files:
160
+ - spec/fixtures/collection.json
161
+ - spec/fixtures/collections.json
162
+ - spec/fixtures/document.json
163
+ - spec/fixtures/documents.json
164
+ - spec/fixtures/engine.json
165
+ - spec/fixtures/engines.json
166
+ - spec/fixtures/version.json
167
+ - spec/helper.rb
168
+ - spec/spec_helper.rb
169
+ - spec/tinysou/client/collections_spec.rb
170
+ - spec/tinysou/client/documents_spec.rb
171
+ - spec/tinysou/client/engines_spec.rb
172
+ - spec/tinysou/client/search_spec.rb
173
+ - spec/tinysou/client_spec.rb