ohmage 0.0.29 → 0.0.31

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: 8fb497c26c555cb4c32f7228fc0720bfa867d116
4
- data.tar.gz: 9b7a484afa92be7e62c15bb991cfe17c767b104f
3
+ metadata.gz: f5f9677fb88f190228aef217b6059f9428b72e26
4
+ data.tar.gz: eca7f33f07ed44bf775dc2bb6b84d8960f8770bf
5
5
  SHA512:
6
- metadata.gz: 215bfc952f9d7fdfda7a49b12767d2344e4ac2f30eac70f27f1d079cd111074306cbd669d55914b89b407829a47b16f4756fa22b507d91d245dcce11dce85947
7
- data.tar.gz: ad3b8db1d56c15e80dea8af77760922c3cc41123c3269aaa0b0eb35a71ae36c0d6e467cac41be88d45e5e814ed104798beba44e9d58c4e89500db8fa876e3a30
6
+ metadata.gz: 960caa295abb04ad70485681472a2f4be3c58a5f7b30eb321b5ec8f042c2deea873f7be1716d2497cda42f60f4fe75468c73e7386b0b69fb9098e14699e321ac
7
+ data.tar.gz: 3fc728c45d14a81f0e62f380180dc862493608df02b27748de659074ea3ab52b5794a7d5b5271f84857ca3d622f250143634d3f9621eb48b8f002c0a83cce29a
@@ -10,6 +10,7 @@ require 'ohmage/entity/campaign'
10
10
  require 'ohmage/entity/document'
11
11
  require 'ohmage/entity/survey'
12
12
  require 'ohmage/entity/audit'
13
+ require 'ohmage/entity/annotation'
13
14
  require 'ohmage/version'
14
15
 
15
16
  module Ohmage
@@ -0,0 +1,65 @@
1
+ module Ohmage
2
+ module API
3
+ module Annotation
4
+ #
5
+ # ohmage annotation/survey_response/create call
6
+ # @see https://github.com/ohmage/server/wiki/
7
+ # @returns [Array: Ohmage::Annotation objects] matching criteria and output format
8
+ #
9
+ def annotation_survey_response_create(params = {})
10
+ request = Ohmage::Request.new(self, :post, 'annotation/survey_response/create', params)
11
+ request.perform
12
+ end
13
+
14
+ #
15
+ # ohmage annotation/prompt_response/create call
16
+ # @see https://github.com/ohmage/server/wiki/
17
+ # @returns [Array: Ohmage::Annotation objects] matching criteria and output format
18
+ #
19
+ def annotation_prompt_response_create(params = {})
20
+ request = Ohmage::Request.new(self, :post, 'annotation/prompt_response/create', params)
21
+ request.perform
22
+ end
23
+
24
+ #
25
+ # ohmage annotation/survey_response/read call
26
+ # @see https://github.com/ohmage/server/wiki/
27
+ # @returns [Array: Ohmage::Annotation objects] matching criteria and output format
28
+ #
29
+ def annotation_survey_response_read(params = {})
30
+ request = Ohmage::Request.new(self, :post, 'annotation/survey_response/read', params)
31
+ # TODO: make a utility to abstract creation of array of base objects
32
+ t = []
33
+ request.perform[:data].each do |k, v|
34
+ t << Ohmage::Annotation.new(k => v)
35
+ end
36
+ t
37
+ end
38
+
39
+ #
40
+ # ohmage annotation/prompt_response/read call
41
+ # @see https://github.com/ohmage/server/wiki/
42
+ # @returns [Array: Ohmage::Annotation objects] matching criteria and output format
43
+ #
44
+ def annotation_prompt_response_read(params = {})
45
+ request = Ohmage::Request.new(self, :post, 'annotation/prompt_response/read', params)
46
+ # TODO: make a utility to abstract creation of array of base objects
47
+ t = []
48
+ request.perform[:data].each do |k, v|
49
+ t << Ohmage::Annotation.new(k => v)
50
+ end
51
+ t
52
+ end
53
+
54
+ #
55
+ # ohmage annotation/delete call
56
+ # @see https://github.com/ohmage/server/wiki/
57
+ # @returns success/fail
58
+ #
59
+ def annotation_delete(params = {})
60
+ request = Ohmage::Request.new(self, :post, 'annotation/delete', params)
61
+ request.perform
62
+ end
63
+ end
64
+ end
65
+ end
@@ -5,6 +5,7 @@ require 'ohmage/document'
5
5
  require 'ohmage/media'
6
6
  require 'ohmage/survey'
7
7
  require 'ohmage/audit'
8
+ require 'ohmage/annotation'
8
9
 
9
10
  module Ohmage
10
11
  module API
@@ -15,5 +16,6 @@ module Ohmage
15
16
  include Ohmage::API::Media
16
17
  include Ohmage::API::Survey
17
18
  include Ohmage::API::Audit
19
+ include Ohmage::API::Annotation
18
20
  end
19
21
  end
@@ -80,12 +80,12 @@ module Ohmage
80
80
  option :class_role, type: :string, desc: 'class_role param: like urn:class:public;reader'
81
81
  option :campaign_role, type: :string, desc: 'campaign_role param: like urn:campaign:snack;reader'
82
82
  def document(file) # rubocop:disable all
83
- case options[:share]
84
- when false
85
- privacy_state = 'private'
86
- else
87
- privacy_state = 'shared'
88
- end
83
+ privacy_state = case options[:share]
84
+ when false
85
+ 'private'
86
+ else
87
+ 'shared'
88
+ end
89
89
  if options[:campaign_role].nil? && options[:class_role].nil?
90
90
  puts 'must supply one of [--class_role, --campaign_role]'
91
91
  elsif options[:name].nil?
@@ -0,0 +1,14 @@
1
+ module Ohmage
2
+ class Annotation
3
+ # @return [String]
4
+ attr_reader :time, :timezone, :annotation_id, :text, :author
5
+ alias_method :id, :annotation_id
6
+ alias_method :urn, :annotation_id
7
+
8
+ def initialize(attrs = {})
9
+ attrs.keys[0].each do |k, v|
10
+ instance_variable_set("@#{k}", v)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -7,7 +7,7 @@ module Ohmage
7
7
  attr_reader :user_roles, :classes
8
8
  alias_method :roles, :user_roles
9
9
  # @return [Hash]
10
- attr_reader :user_role_campaign
10
+ attr_reader :user_role_campaign, :survey_response_count
11
11
 
12
12
  def initialize(attrs = {})
13
13
  @urn = attrs.keys[0].to_s
@@ -1,7 +1,7 @@
1
1
  module Ohmage
2
2
  class SurveyResponse
3
3
  # @return [String]
4
- attr_reader :client, :privacy_state, :repeatable_set_id, :repeatable_set_iteration, :survey_description, :survey_id, :survey_title, :user, :timezone
4
+ attr_reader :urn, :client, :privacy_state, :repeatable_set_id, :repeatable_set_iteration, :survey_description, :survey_id, :survey_title, :user, :timezone
5
5
  # @return [String] location stuffz
6
6
  attr_reader :location_accuracy, :location_provider, :location_status, :location_timestamp
7
7
  # @return [Long]
@@ -32,7 +32,7 @@ module Ohmage
32
32
  502 => Ohmage::Error::BadGateway,
33
33
  503 => Ohmage::Error::ServiceUnavailable,
34
34
  504 => Ohmage::Error::GatewayTimeout
35
- }
35
+ }.freeze
36
36
  # How ugly is this??
37
37
  STRING_ERRORS = {
38
38
  '0100' => Ohmage::Error::InternalServerError,
@@ -68,35 +68,6 @@ module Ohmage
68
68
  STRING_ERRORS[e] = Ohmage::Error::CatchAll
69
69
  end
70
70
  class << self
71
- # Create a new error from an HTTP response
72
- #
73
- # @param body [String]
74
- # @return [Ohmage::Error]
75
- def from_response(body)
76
- message, code = parse_error(body)
77
- # ohmage returns own error codes in body and as strings.
78
- if code.is_a? String
79
- new(message, 888)
80
- else
81
- new(message, code)
82
- end
83
- end
84
-
85
- private
86
-
87
- def parse_error(body)
88
- if body.nil? || body.empty?
89
- ['', nil]
90
- elsif body[:errors]
91
- extract_message_from_errors(body)
92
- end
93
- end
94
-
95
- def extract_message_from_errors(body)
96
- first = Array(body[:errors]).first
97
- [first[:text], first[:code]]
98
- end
99
- end
100
71
  # Initializes a new Error object
101
72
  #
102
73
  # @param message [Exception, String]
@@ -107,5 +78,37 @@ module Ohmage
107
78
  super(message)
108
79
  @code = code
109
80
  end
81
+
82
+ # Create a new error from an HTTP response
83
+ #
84
+ # @param body [String]
85
+ # @return [Ohmage::Error]
86
+ def from_response(body)
87
+ message, code = parse_error(body)
88
+ # ohmage returns own error codes in body and as strings.
89
+ if code.is_a? String
90
+ # some bug in catchall already sets this?
91
+ # error class really needs a refactor.
92
+ new(message)
93
+ else
94
+ new(message, code)
95
+ end
96
+ end
97
+
98
+ private
99
+
100
+ def parse_error(body)
101
+ if body.nil? || body.empty?
102
+ ['', nil]
103
+ elsif body[:errors]
104
+ extract_message_from_errors(body)
105
+ end
106
+ end
107
+
108
+ def extract_message_from_errors(body)
109
+ first = Array(body[:errors]).first
110
+ [first[:text], first[:code]]
111
+ end
112
+ end
110
113
  end
111
114
  end
@@ -52,7 +52,7 @@ module Ohmage
52
52
  def survey_upload(params = {})
53
53
  # loop around params, finding attached images/files, set them as form data.
54
54
  params.each do |param|
55
- if /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/.match(param.first)
55
+ if /[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/ =~ param.first
56
56
  @mime_type = /[^;]*/.match(`file -b --mime "#{param[1]}"`)[0]
57
57
  params[param[0]] = HTTP::FormData::File.new(param[1], mime_type: @mime_type)
58
58
  end
@@ -75,7 +75,7 @@ module Ohmage
75
75
  #
76
76
  # ohmage user/search call. Admin only api
77
77
  # @see https://github.com/ohmage/server/wiki/User-Manipulation#userSetup
78
- # @returns Array of Ohmage::User objects.
78
+ # @returns Array of Ohmage::User objects.
79
79
  #
80
80
  def user_search(params = {})
81
81
  request = Ohmage::Request.new(self, :post, 'user/search', params)
@@ -14,7 +14,7 @@ module Ohmage
14
14
 
15
15
  # @return [Integer]
16
16
  def patch
17
- 29
17
+ 31
18
18
  end
19
19
 
20
20
  # @return [Integer, NilClass]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohmage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.29
4
+ version: 0.0.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Nolen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -77,6 +77,7 @@ files:
77
77
  - LICENSE.txt
78
78
  - bin/ohmage
79
79
  - lib/ohmage.rb
80
+ - lib/ohmage/annotation.rb
80
81
  - lib/ohmage/api.rb
81
82
  - lib/ohmage/audit.rb
82
83
  - lib/ohmage/campaign.rb
@@ -85,6 +86,7 @@ files:
85
86
  - lib/ohmage/cli_helpers.rb
86
87
  - lib/ohmage/client.rb
87
88
  - lib/ohmage/document.rb
89
+ - lib/ohmage/entity/annotation.rb
88
90
  - lib/ohmage/entity/audit.rb
89
91
  - lib/ohmage/entity/campaign.rb
90
92
  - lib/ohmage/entity/clazz.rb