ohmage 0.0.5 → 0.0.7

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11562ee88ee211a26b1de51f1d85381b7dca6348
4
- data.tar.gz: be85538fa68335913b62a27aad4df53255075cc0
3
+ metadata.gz: 59ab780b8079f500ce47352892b7decd6e1c0ef8
4
+ data.tar.gz: f7055a09f90ef2c8643c6977a115dae2fbdc9f11
5
5
  SHA512:
6
- metadata.gz: e15077337892ceccd71a69d8dc6a355b668773f78cabb4ccb8781cb2830d22f1a2037f550c3132d897c4349828672a478179a4625dc9bc6fe8e806e7acebc538
7
- data.tar.gz: 8f953a4382d2d9828180a1c1d9c9b38a0713120a6b62141662cf924e1ee400b7abcc190f115199b2eef01ee37d65b24ffb0be20bbf7e78405f2cfb8391bb18a0
6
+ metadata.gz: df90c35418b29eeea0e4fb2a7ef80c0f11591e363204123fd214a2b5285ce8ce798026d9a66ff866df052363740199aa61e1faf2fc4460db55dac3e4b8d0b5b7
7
+ data.tar.gz: ba6990e6bb8bb75fb477d405f63dbf85a8057a2be5dc95ce753ef0db4dd112e9d80027748cc7cca315883820ecdc3cf9ab4b7cc0d0be886b37ddade14c7bfbf2
data/lib/ohmage.rb CHANGED
@@ -7,6 +7,7 @@ require 'ohmage/request'
7
7
  require 'ohmage/entity/user'
8
8
  require 'ohmage/entity/clazz'
9
9
  require 'ohmage/entity/campaign'
10
+ require 'ohmage/entity/document'
10
11
  require 'ohmage/version'
11
12
 
12
13
  module Ohmage
data/lib/ohmage/api.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  require 'ohmage/user'
2
2
  require 'ohmage/campaign'
3
3
  require 'ohmage/clazz'
4
+ require 'ohmage/document'
4
5
 
5
6
  module Ohmage
6
7
  module API
7
8
  include Ohmage::API::User
8
9
  include Ohmage::API::Clazz
9
10
  include Ohmage::API::Campaign
11
+ include Ohmage::API::Document
10
12
  end
11
13
  end
data/lib/ohmage/cli.rb CHANGED
@@ -21,7 +21,7 @@ module Ohmage
21
21
  ls = Ohmage.class_read(class_urn_list: urn_list)
22
22
  Ohmage::CliHelpers.format_output(ls, options[:table], [:name, :urn, :description, :role, :users], :urn)
23
23
  end
24
- map :class => :clazz
24
+ map class: :clazz
25
25
 
26
26
  desc 'ls user <options>', 'Lists users that match criteria of search, all viewable if no search'
27
27
  option :search, aliases: :s, desc: 'a search string to limit the returned user list'
@@ -56,7 +56,7 @@ module Ohmage
56
56
  description: options[:description])
57
57
  Ohmage::CliHelpers.format_output(new_class, options[:table], [:urn, :name, :description], :urn)
58
58
  end
59
- map :class => :clazz
59
+ map class: :clazz
60
60
  end
61
61
 
62
62
  class Delete < Thor
@@ -64,7 +64,7 @@ module Ohmage
64
64
  def clazz(urn)
65
65
  Ohmage.class_delete(class_urn: urn)
66
66
  end
67
- map :class => :clazz
67
+ map class: :clazz
68
68
 
69
69
  desc 'delete user <username>', 'deletes an existing ohmage user'
70
70
  def user(username)
@@ -0,0 +1,28 @@
1
+ module Ohmage
2
+ module API
3
+ module Document
4
+ #
5
+ # ohmage document/read call
6
+ # @see https://github.com/ohmage/server/wiki/Document-Manipulation#document-information-read
7
+ # @returns [Array: Ohmage::Document objects] matching criteria and output format
8
+ def document_read(params = {})
9
+ request = Ohmage::Request.new(self, :post, 'document/read', params)
10
+ # TODO: make a utility to abstract creation of array of base objects
11
+ t = []
12
+ request.perform[:data].each do |k, v|
13
+ t << Ohmage::Document.new(k => v)
14
+ end
15
+ t
16
+ end
17
+
18
+ def document_create(file, params = {})
19
+ params[:document] = HTTP::FormData::File.new(file)
20
+ # catch lack of document_name param, since we can just append the filename we have!
21
+ params[:document_name] = File.basename(file) unless params.key?(:document_name)
22
+ request = Ohmage::Request.new(self, :post, 'document/create', params)
23
+ request.perform
24
+ document_read(document_name_search: params[:document_name])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ module Ohmage
2
+ class Document
3
+ # @return [String]
4
+ attr_reader :urn, :name, :size, :user_max_role, :user_role, :privacy_state, :last_modified, :description
5
+ alias_method :id, :urn
6
+ # @return [Hash]
7
+ attr_reader :campaign_role, :class_role
8
+
9
+ def initialize(attrs = {})
10
+ @urn = attrs.keys[0].to_s
11
+ attrs.values[0].each do |k, v|
12
+ instance_variable_set("@#{k}", v)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -14,9 +14,16 @@ module Ohmage
14
14
  end
15
15
 
16
16
  @request_method = request_method
17
+ # some create/upload apis require content to be sent as multipart form. catch that here
18
+ case api
19
+ when 'document/create', 'survey/upload'
20
+ @params = {form: @options}
21
+ else
22
+ @params = {params: @options}
23
+ end
17
24
  end
18
25
  def perform # rubocop:disable all
19
- response = HTTP.public_send(@request_method, @uri.to_s, params: @options)
26
+ response = HTTP.public_send(@request_method, @uri.to_s, @params)
20
27
  response_body = symbolize_keys!(response.parse)
21
28
  response_headers = response.headers
22
29
  begin
@@ -14,7 +14,7 @@ module Ohmage
14
14
 
15
15
  # @return [Integer]
16
16
  def patch
17
- 5
17
+ 7
18
18
  end
19
19
 
20
20
  # @return [Integer, NilClass]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohmage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Nolen
@@ -83,8 +83,10 @@ files:
83
83
  - lib/ohmage/cli.rb
84
84
  - lib/ohmage/cli_helpers.rb
85
85
  - lib/ohmage/client.rb
86
+ - lib/ohmage/document.rb
86
87
  - lib/ohmage/entity/campaign.rb
87
88
  - lib/ohmage/entity/clazz.rb
89
+ - lib/ohmage/entity/document.rb
88
90
  - lib/ohmage/entity/user.rb
89
91
  - lib/ohmage/error.rb
90
92
  - lib/ohmage/request.rb