camlistore 0.0.1 → 0.0.2

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 CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- Y2JlYWUyODNiNjdhMzBmYTQ5NzE3NjAxYWRmMjI4ZjEzNDUwMDg4YQ==
5
- data.tar.gz: !binary |-
6
- NDI3NzVkZDBlNDU1NzhiNGNhZDc4ZmE1N2Q1NTM5MmViZWI1NDJmMw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MzMwYjRiMWNhNjdkMWU3ZmNkNmU3MmM4MmE4MDc1MDljNTBiYzU0OThjNTM2
10
- M2U5ODIyMTcwZTk4YzMyMzIxMDE3OGJkMjRkMjVmMDU5ZTlkZWJkYWNhOTk3
11
- NDQ4MTE1NGVkMTYwNzVkMmMyZjc3ZmE4MzA5OGNjZDcyMzBkOWE=
12
- data.tar.gz: !binary |-
13
- YjhlNDUyYTI0ZjdhM2UwZWI2NTA2MTdhMjgwYzNkZTAzZjQwMzI1MjVjMjg5
14
- NmU3YTBlOWVlODFmZjVkM2UyYWM2MzNjM2FkODAwY2Q5MGFjYWMyNDE1NDAy
15
- NDk4MzFmZWQ4MDQxNzBlMTZmZjhmZDkwNjdmZTE5NjdhNjY4ODE=
2
+ SHA1:
3
+ metadata.gz: efa7c94d5b87809a153c69a9f8de65456c707464
4
+ data.tar.gz: af9f070609707f40e5164106c38df07f13e4aba6
5
+ SHA512:
6
+ metadata.gz: a53893d9812102fcebdcb4cd5ebc738d53702722ae763e2ff4fe4d6c4f6411e2abcf718baa3072eb2b2c1ddb1d0c175faf7447fa85f846a23fba957f04f98840
7
+ data.tar.gz: 895512a4f6bb0989755d8b9dc53aa05c0235c29aa2bc4bf24a66b9acbd7c292591299be53af034331a586c1840fdfee45bb58ea0ce7039b9a2c2644cb8458880
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
data/README.md CHANGED
@@ -7,4 +7,8 @@ require 'camlistore'
7
7
  camli = Camlistore.new
8
8
  result = camli.enumerate_blobs(limit: 1)
9
9
  result.blobs.first.blobRef # => "sha1-..."
10
+
11
+ camli.find_each do |sha|
12
+ camli.get(sha) # => some data
13
+ end
10
14
  ```
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
  gem.add_runtime_dependency 'faraday_middleware', '~> 0.9.0'
20
+ gem.add_runtime_dependency 'activesupport', '>= 4.0.0'
20
21
  end
@@ -5,6 +5,8 @@ require 'active_support/core_ext/object/blank'
5
5
  require 'active_support/core_ext/array/wrap'
6
6
  require 'active_support/core_ext/string/inflections'
7
7
  require 'active_support/concern'
8
+ require 'digest/sha1'
9
+ require 'json'
8
10
 
9
11
  module Camlistore
10
12
  autoload :Configuration, 'camlistore/configuration'
@@ -4,15 +4,35 @@ module Camlistore
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  def connection
7
- @connection ||= Faraday.new(config.bshost) do |conn|
7
+ @connection ||= Faraday.new(config.host) do |conn|
8
8
  conn.response :mashify
9
9
  conn.response :json, content_type: 'text/javascript'
10
10
  conn.adapter Faraday.default_adapter
11
11
  end
12
12
  end
13
13
 
14
- def api_call url, params = {}
15
- response = connection.get(url, params)
14
+ def api_call url, params = {}, headers = {}
15
+ response = connection.get(url, params, headers) do |conn|
16
+ yield(conn) if block_given?
17
+ end
18
+
19
+ data = response.body
20
+
21
+ # Camlistore doesn't seem to give errors?
22
+ # error_message = data.error_message
23
+ # raise ArgumentError, error_message if error_message
24
+
25
+ if block_given?
26
+ yield data
27
+ else
28
+ data
29
+ end
30
+ end
31
+
32
+ def api_post url, params = {}, headers = {}
33
+ response = connection.post(url, params, headers) do |conn|
34
+ yield(conn) if block_given?
35
+ end
16
36
 
17
37
  data = response.body
18
38
 
@@ -1,18 +1,21 @@
1
1
  module Camlistore
2
2
  Configuration.namespace :camlistore
3
- Configuration.keys :bshost
3
+ Configuration.keys :host
4
4
  Configuration.env ENV
5
5
 
6
6
  class Client
7
- attr_reader :config
7
+ attr_reader :config, :blobroot, :searchroot
8
8
  include API
9
9
 
10
10
  def initialize options = {}
11
- @config = Configuration.new(options, bshost: 'http://localhost:3179/bs/')
12
- raise ArgumentError, "You must supply blobstore host." unless config.bshost.present?
11
+ @config = Configuration.new(options, host: 'http://localhost:3179')
12
+ raise ArgumentError, "You must supply blobstore host." unless config.host.present?
13
+ remote_configuration = api_call '/', {}, {accept: 'text/x-camli-configuration'}
14
+ @blobroot = remote_configuration['blobRoot']
15
+ @searchroot = remote_configuration['searchRoot']
13
16
  end
14
17
 
15
- api_method :enumerate_blobs, 'camli/enumerate-blobs'
18
+ api_method :enumerate_blobs, '/bs/camli/enumerate-blobs'
16
19
 
17
20
  def each_blob &block
18
21
  data = enumerate_blobs
@@ -30,8 +33,36 @@ module Camlistore
30
33
  end
31
34
  end
32
35
 
36
+ def blobref content
37
+ 'sha1-' + Digest::SHA1.hexdigest(content)
38
+ end
39
+
33
40
  def get sha
34
- api_call('camli/' + sha)
41
+ api_call(@blobroot + 'camli/' + sha)
42
+ end
43
+
44
+ def describe sha
45
+ api_call(@searchroot + 'camli/search/describe', {'blobref' => sha})
46
+ end
47
+
48
+ def search query
49
+ query = query.to_json if query.is_a?(Hash)
50
+ api_post(@searchroot + 'camli/search/query', query)
51
+ end
52
+
53
+ def put content
54
+ sha = blobref(content)
55
+ boundary = 'randomboundaryXYZ'
56
+ content_type = "multipart/form-data; boundary=#{boundary}"
57
+
58
+ post_body = "--#{boundary}
59
+ Content-Disposition: form-data; name='#{sha}'; filename='#{sha}'
60
+ Content-Type: application/octet-stream
61
+
62
+ #{content}
63
+ --#{boundary}--"
64
+
65
+ api_post(@blobroot + 'camli/upload', post_body, {:content_type => content_type})
35
66
  end
36
67
  end
37
68
 
@@ -1,3 +1,3 @@
1
1
  module Camlistore
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,36 +1,51 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: camlistore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Quinn Shanahan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-12 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.9.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.0.0
27
41
  description: Some access to your camlistore in ruby
28
42
  email: quinn@tastehoneyco.com
29
43
  executables: []
30
44
  extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
33
- - .gitignore
47
+ - ".gitignore"
48
+ - Gemfile
34
49
  - LICENSE
35
50
  - README.md
36
51
  - camlistore.gemspec
@@ -48,17 +63,17 @@ require_paths:
48
63
  - lib
49
64
  required_ruby_version: !ruby/object:Gem::Requirement
50
65
  requirements:
51
- - - ! '>='
66
+ - - ">="
52
67
  - !ruby/object:Gem::Version
53
68
  version: '0'
54
69
  required_rubygems_version: !ruby/object:Gem::Requirement
55
70
  requirements:
56
- - - ! '>='
71
+ - - ">="
57
72
  - !ruby/object:Gem::Version
58
73
  version: '0'
59
74
  requirements: []
60
75
  rubyforge_project:
61
- rubygems_version: 2.0.7
76
+ rubygems_version: 2.2.2
62
77
  signing_key:
63
78
  specification_version: 4
64
79
  summary: Camlistore client