manifestly-client 0.0.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 636afd68b4507041c22815fd31b8952d94c5b849b2a1cb5dfad870005d1254c1
4
- data.tar.gz: b1ded85331108c971a6643494b6b39b4b5ec110169858ab05ff09a05febae554
3
+ metadata.gz: 9cd08e5fcf5d6cc1c5784fb8ccc8b9276d83fee49223236754a40834a312cddb
4
+ data.tar.gz: 0cad3e6e1d87522fcc87ed716fae04b4f5f2c8f99ffce4f95713b0400584372b
5
5
  SHA512:
6
- metadata.gz: aafcd3b3735ff5fe8eb97c300a69ef8664c861ea00f929886c4ef6e2f2888f9a176fc86490009d988418a50747eb653ebb2de4b024d5ba46c674273965d5040a
7
- data.tar.gz: '025857d602d440a7e858482a59c334873ffe303de082b81b01755e7fadcecdd62e7f1826324ae1da98d68b29d8fbd98ab0f453779ea6f6f586284761b93c9e64'
6
+ metadata.gz: 21974177cd03dad15708b1dff4e6a6a3d5039866827d8061574ab621586e95300663428ccdfad012d83846e19564411eaaf62685013b83dc407885646092c605
7
+ data.tar.gz: 2351717f5e532bc4ce0d504be33ad3e8273100b87ff45ae6a7ead9ee2e8462c4b5db09b5f56426703aaea938dbf9231b1e0a69d90da9578e472a33c67a1fd611
data/.travis.yml CHANGED
@@ -2,9 +2,18 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm: 2.4
4
4
  script:
5
+ - bundle exec bundle-audit update && bundle exec bundle-audit check
5
6
  - bundle exec rspec spec/unit
6
7
  - bundle exec rubocop
7
8
  deploy:
9
+ - provider: releases
10
+ api_key:
11
+ secure: ljBnXvc8L+BxeJshZ5+67vsEp5ixShklubZ2/fqqMN1jscgzkjXYmr5+Vr06ndiK4pnorZRIXYK0CZHye8+Yf8OJCLHss+6/pToE2Dw+WkBCWPrq7TJzd5G3hufTyMJ4nNdXmrJqYYmZi6SYvLLdK/7m738wdumHmT+OGH4XPi1Rl6KaPnrnqI4Jlrbdmg6w0Nq7EELh5tjlJjjJ2U4XN7+NzsDJJixjizsiKA66vzfhjSJ56gZe6L+GRtkbT3BIq9bK+YYpTDbuXiQWM4opdK/OLnoWTLRlnerrVwrV1vlWRdXMJe5S24jiiFX5a7mop8gLfSQICXRrfgt3U/+2H405khf5ahwIwqZm7N4ebQOW4MCKedjlvBD4+SInghCYs6HKczhnhiDqQwQsL/YKf3l81LjuAbabv/iFNrjFcVip06E567YIWkSb/PM6QkHKXBzf9koahF6Vg3P9msw1fvc5EcYeyiuiqv7+wTZVKz+7NJkO7az92Vahb99qIW4/RlSmYmS9uTo6CfJ1k8ZdoJSLEq6kXKxFryCQ7g+3Lwh8GVdgZuGgPelLVMV8TitP6D0KNu8cXD6Mugpf+f5p2ZoZGbGOQYdrNOA72MrHAI+SCcM6E/QUAz4e9t5S3EA8+x2Ns3rAmi6Wxuae45o8ovghlyQsfGFlr48pfuHCSic=
12
+ file_glob: true
13
+ file: manifestly-client-*.gem
14
+ on:
15
+ tags: true
16
+ repo: firespring/manifestly-ruby
8
17
  - provider: rubygems
9
18
  api_key:
10
19
  secure: FRUmy4P70d/oNd4Kom5af5NJ+6bqf4fJUrVZJGU1j+j5GjNNUTVsXdN+FU3nRgiukGxplYl48/RMDnfmEAkgLtF21lKp2f081LOuJ1PaaO3UquNIUULYrrxSu+zWHfdx6B9IZKVVxMmX1y+gb1z8TxhNpkZsfeu+uo3kjyESX4NHYxLSmPsjMhTnxnzspZ996PudDSrw4IGwWDkQ6Tkcn0mL0EhTUjmL6/HGJ+0U0vCh3GMbTw8jYcp76nUjn6mc1nmJ2HebnkZVKchoWOWwH7wOBmY8tDZZqohE0XJsOTGBf3ogZlZJCI/NmvlfP0DWuSPER92/4ew7wKeOIxHGwPXNtG4s7ttMGiR2d0XeIrT2OLj++5nNo2dGX9WcWtOq3605Eu9lyY7aT8aQLqO+jR1lV2FfNnh2Uw/SnKjYUAF4k36/D0MFS1dW8y/FqsA0U++M1Vo6dWxqnmQdhyFRiH+6kJOVIq1peZiXWhPqY+soLk5iS7M8AEg1yBRkfBFYjHETSkQJqVWZ6khabRtPdQe22kmc9VqbhksU6dT6Hq4gwEoVpzGWv4IBrHawMwO4sY41Is6fL1R9ypFCdqtH4ZAtb33TC1HFzD6vrPciVXRrcuuZY4pKHtOK/fnw1Va2zYmREmTGi71jNN9oj7ItyxCXCl3pu53cScS6w7cYxbY=
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :development, :test do
6
+ gem 'bundler-audit'
6
7
  gem 'factory_bot'
7
8
  gem 'faker'
8
9
  gem 'rspec'
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Manifest.ly Ruby Client
2
+ [![Gem Version](https://badge.fury.io/rb/manifestly-client.svg)](https://badge.fury.io/rb/manifestly-client)
3
+ [![Build Status](https://api.travis-ci.org/firespring/manifestly-ruby.svg?branch=master)](https://travis-ci.org/firespring/manifestly-ruby)
2
4
 
3
5
  A Ruby client that enables quick and easy interactions with the Manifest.ly api.
4
6
 
@@ -34,14 +36,14 @@ puts Manifestly::Entity::Workflow.list.inspect
34
36
 
35
37
  You may create a new workflow by passing a hash of data to the Workflow constructor and invoking the `create` method. Some internal fields (like `id`) will be injected back in to the object after it is created.
36
38
  ```ruby
37
- data = {title: 'Test Workflow'}
39
+ data = {title: 'Test Workflow', external_id: 'abc123'}
38
40
  workflow = Manifestly::Entity::Workflow.new(data).create
39
41
  workflow.create
40
42
  ```
41
43
 
42
44
  If you specify an `external_id` for a local reference, Manifest.ly will use an `upsert` methodology (if the workflow does not exist it will be created - otherwise it will be updated). This effectively means that create/update/save function identically for workflows.
43
45
  ```ruby
44
- data = {title: 'Test Workflow with External Id', external_id: 'abc123'}
46
+ data = {title: 'Test Workflow Upsert', external_id: 'def456'}
45
47
  workflow = Manifestly::Entity::Workflow.new(data).create
46
48
 
47
49
  workflow.title = "#{workflow.title} (updated)"
@@ -50,7 +52,7 @@ workflow.create
50
52
 
51
53
  You may delete a workflow if you specified an external_id when creating it.
52
54
  ```ruby
53
- data = {title: 'Test Workflow Delete', external_id: 'def456'}
55
+ data = {title: 'Test Workflow Delete', external_id: 'ghi789'}
54
56
  workflow = Manifestly::Entity::Workflow.new(data).create
55
57
  workflow.delete
56
58
  ```
@@ -59,7 +61,7 @@ workflow.delete
59
61
 
60
62
  Steps may be passed in when creating a workflow via the steps field.
61
63
  ```ruby
62
- data = {title: 'Test Workflow with steps', external_id: 'ghi789', steps: [{title: 'Step One'}]}
64
+ data = {title: 'Test Workflow with steps', external_id: 'jkl012', steps: [{title: 'Step One'}]}
63
65
  workflow = Manifestly::Entity::Workflow.new(data)
64
66
  workflow.create
65
67
  ```
@@ -71,11 +73,10 @@ You may start a new checklist run by passing a hash of data to the ChecklistRun
71
73
  my_email_address = 'john.smith@foo.bar'
72
74
  my_user = Manifestly::Entity::User.list.find { |it| it.email == my_email_address }
73
75
 
74
- title = 'Test Workflow with steps'
75
- workflows = Manifestly::Entity::Workflow.list
76
- workflow = workflows.find { |it| it.title == title }
76
+ data = {title: 'Test Workflow for checklist run', external_id: 'mno345', steps: [{title: 'Step One'}]}
77
+ workflow = Manifestly::Entity::Workflow.new(data).create
77
78
 
78
- data = {title: "Test Run", checklist_id: workflow.id, users: [my_user.id]}
79
+ data = {title: 'Test Run', checklist_id: workflow.id, users: [my_user.id]}
79
80
  checklist_run = Manifestly::Entity::ChecklistRun.new(data).create
80
81
  ```
81
82
 
@@ -84,11 +85,14 @@ You may complete a checklist step by calling the corresponding method on the ste
84
85
  my_email_address = 'john.smith@foo.bar'
85
86
  my_user = Manifestly::Entity::User.list.find { |it| it.email == my_email_address }
86
87
 
87
- checklist = Manifestly::Entity::ChecklistRun.list(title: 'Test Run', status: :started).first
88
- step = checklist.steps.first
88
+ data = {title: 'Test Workflow for checklist run step complete', external_id: 'pqr678', steps: [{title: 'Step One'}]}
89
+ workflow = Manifestly::Entity::Workflow.new(data).create
90
+
91
+ data = {title: 'Test Run step complete', checklist_id: workflow.id, users: [my_user.id]}
92
+ checklist_run = Manifestly::Entity::ChecklistRun.new(data).create
89
93
 
90
- step.assign(my_user.id)
91
- step.complete
94
+ checklist_run.steps.first.assign(my_user.id)
95
+ checklist_run.steps.first.complete
92
96
  ```
93
97
 
94
98
  ## Supported Ruby Versions
@@ -25,8 +25,8 @@ module Manifestly
25
25
  attr_reader :users
26
26
  attr_accessor :origin
27
27
 
28
- def self.path
29
- 'runs'
28
+ def self.endpoint_target
29
+ :runs
30
30
  end
31
31
 
32
32
  def users=(values)
@@ -39,7 +39,10 @@ module Manifestly
39
39
  end
40
40
 
41
41
  def steps
42
- @steps ||= Manifestly::Entity::ChecklistStep.list(self)
42
+ return @steps if @steps
43
+
44
+ @steps = Manifestly::Entity::ChecklistRunStep.list(self) if id
45
+ @steps ||= []
43
46
  end
44
47
  end
45
48
  end
@@ -3,7 +3,7 @@ require 'date'
3
3
 
4
4
  module Manifestly
5
5
  module Entity
6
- class ChecklistStep < Endpoint
6
+ class ChecklistRunStep < ChildEndpoint
7
7
  attr_accessor :id
8
8
  attr_accessor :assignee_avatar_url
9
9
  attr_accessor :assignee_id
@@ -32,11 +32,12 @@ module Manifestly
32
32
  invalid_method(:save)
33
33
  invalid_method(:delete)
34
34
 
35
- def initialize(run, data = {})
36
- raise 'invalid checklist run' unless run.is_a?(ChecklistRun)
35
+ def self.parent_class
36
+ ChecklistRun
37
+ end
37
38
 
38
- @parent = run
39
- super(data)
39
+ def self.endpoint_target
40
+ :run_steps
40
41
  end
41
42
 
42
43
  # Header step needs to always be a boolean (even if not set)
@@ -49,60 +50,50 @@ module Manifestly
49
50
  @header_step = (value.to_s == 'true')
50
51
  end
51
52
 
52
- def self.path
53
- 'run_steps'
54
- end
55
-
56
- def self.list(run)
57
- response = client.get("#{run.path}/#{run.id}/#{path}")
58
- json_entities = JSON.parse(response[:body], symbolize_names: true)[path.to_sym]
59
- json_entities.map { |it| new(run, it) }
60
- end
61
-
62
53
  def complete
63
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/complete")
54
+ client.post("#{location}/#{id}/complete")
64
55
  @parent.instance_variable_set(:@steps, nil)
65
56
  nil
66
57
  end
67
58
 
68
59
  def uncomplete
69
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/uncomplete")
60
+ client.post("#{location}/#{id}/uncomplete")
70
61
  @parent.instance_variable_set(:@steps, nil)
71
62
  nil
72
63
  end
73
64
 
74
65
  def skip
75
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/skip")
66
+ client.post("#{location}/#{id}/skip")
76
67
  @parent.instance_variable_set(:@steps, nil)
77
68
  nil
78
69
  end
79
70
 
80
71
  def unskip
81
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/unskip")
72
+ client.post("#{location}/#{id}/unskip")
82
73
  @parent.instance_variable_set(:@steps, nil)
83
74
  nil
84
75
  end
85
76
 
86
77
  def add_data(data)
87
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/data", params: {data: data})
78
+ client.post("#{location}/#{id}/data", params: {data: data})
88
79
  @parent.instance_variable_set(:@steps, nil)
89
80
  nil
90
81
  end
91
82
 
92
83
  def add_picture(base_64_encoded_picture_data)
93
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/picture", params: {picture: base_64_encoded_picture_data})
84
+ client.post("#{location}/#{id}/picture", params: {picture: base_64_encoded_picture_data})
94
85
  @parent.instance_variable_set(:@steps, nil)
95
86
  nil
96
87
  end
97
88
 
98
89
  def add_comment(comment)
99
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/comments", params: {comment: comment})
90
+ client.post("#{location}/#{id}/comments", params: {comment: comment})
100
91
  @parent.instance_variable_set(:@steps, nil)
101
92
  nil
102
93
  end
103
94
 
104
95
  def assign(user_id)
105
- client.post("#{@parent.path}/#{@parent.id}/#{path}/#{id}/assign", params: {assignee_user_id: user_id})
96
+ client.post("#{location}/#{id}/assign", params: {assignee_user_id: user_id})
106
97
  @parent.instance_variable_set(:@steps, nil)
107
98
  nil
108
99
  end
@@ -6,12 +6,28 @@ module Manifestly
6
6
  class Endpoint < Base
7
7
  @client = nil
8
8
 
9
- def path
10
- self.class.path
9
+ def self.endpoint_target
10
+ raise 'Must specify endpoint_target'
11
11
  end
12
12
 
13
- def self.path
14
- raise 'Must override method'
13
+ def endpoint_target
14
+ self.class.endpoint_target
15
+ end
16
+
17
+ def self.singular_endpoint_target
18
+ endpoint_target.to_s.chomp('s').to_sym
19
+ end
20
+
21
+ def singular_endpoint_target
22
+ self.class.singular_endpoint_target
23
+ end
24
+
25
+ def location
26
+ self.class.location
27
+ end
28
+
29
+ def self.location
30
+ endpoint_target
15
31
  end
16
32
 
17
33
  def client
@@ -22,26 +38,26 @@ module Manifestly
22
38
  @client ||= Manifestly::Client.new
23
39
  end
24
40
 
25
- def create
41
+ def create(path: location)
26
42
  response = client.post(path, params: to_h)
27
- json_entity = JSON.parse(response[:body], symbolize_names: true)[path.chomp('s').to_sym]
43
+ json_entity = JSON.parse(response[:body], symbolize_names: true)[singular_endpoint_target]
28
44
  self.attributes = json_entity
29
45
  self
30
46
  end
31
47
 
32
- def self.list(**params)
48
+ def self.list(path: location, **params)
33
49
  response = client.get(path, params: params)
34
- json_entities = JSON.parse(response[:body], symbolize_names: true)[path.to_sym]
50
+ json_entities = JSON.parse(response[:body], symbolize_names: true)[endpoint_target]
35
51
  json_entities.map { |it| new(it) }
36
52
  end
37
53
 
38
- def self.get(id)
54
+ def self.get(id, path: location)
39
55
  response = client.get("#{path}/#{id}")
40
- json_entity = JSON.parse(response[:body], symbolize_names: true)[path.chomp('s').to_sym]
56
+ json_entity = JSON.parse(response[:body], symbolize_names: true)[singular_endpoint_target.to_sym]
41
57
  new(json_entity)
42
58
  end
43
59
 
44
- def update
60
+ def update(path: location)
45
61
  client.post("#{path}/#{id}", params: to_h)
46
62
  self
47
63
  end
@@ -54,10 +70,57 @@ module Manifestly
54
70
  end
55
71
  end
56
72
 
57
- def delete
73
+ def delete(path: location)
58
74
  client.delete(path, params: {external_id: external_id})
59
75
  nil
60
76
  end
61
77
  end
78
+
79
+ class ChildEndpoint < Endpoint
80
+ def parent_class
81
+ self.class.parent_class
82
+ end
83
+
84
+ def self.parent_class
85
+ raise 'Must specify parent_class'
86
+ end
87
+
88
+ def initialize(parent, data = {})
89
+ raise "invalid #{parent_class}" unless parent.is_a?(parent_class)
90
+
91
+ @parent = parent
92
+ super(data)
93
+ end
94
+
95
+ def location
96
+ self.class.location(@parent)
97
+ end
98
+
99
+ def self.location(parent)
100
+ "#{parent.location}/#{parent.id}/#{endpoint_target}"
101
+ end
102
+
103
+ def self.list(parent, **params)
104
+ response = client.get(location(parent), params: params)
105
+ json_entities = JSON.parse(response[:body], symbolize_names: true)[endpoint_target]
106
+ json_entities.map { |it| new(parent, it) }
107
+ end
108
+
109
+ def self.get(id, parent)
110
+ response = client.get("#{location(parent)}/#{id}")
111
+ json_entity = JSON.parse(response[:body], symbolize_names: true)[singular_endpoint_target.to_sym]
112
+ new(parent, json_entity)
113
+ end
114
+
115
+ def update(path: location)
116
+ client.put("#{path}/#{id}", params: to_h)
117
+ self
118
+ end
119
+
120
+ def delete(path: location)
121
+ client.delete("#{path}/#{id}")
122
+ nil
123
+ end
124
+ end
62
125
  end
63
126
  end
@@ -18,8 +18,8 @@ module Manifestly
18
18
  invalid_method(:save)
19
19
  invalid_method(:delete)
20
20
 
21
- def self.path
22
- 'users'
21
+ def self.endpoint_target
22
+ :users
23
23
  end
24
24
  end
25
25
  end
@@ -15,8 +15,8 @@ module Manifestly
15
15
  attr_reader :tag_list
16
16
  attr_accessor :title
17
17
 
18
- def self.path
19
- 'checklists'
18
+ def self.endpoint_target
19
+ :checklists
20
20
  end
21
21
 
22
22
  # Workflows use an 'upsert' methodology so the create and update routes are shared.
@@ -28,8 +28,7 @@ module Manifestly
28
28
  def steps # rubocop:disable DuplicateMethods
29
29
  return @steps if @steps
30
30
 
31
- # If you are trying to get the steps on a workflow returned by the `list` functionality,
32
- @steps = self.class.get(id).steps if id
31
+ @steps = Manifestly::Entity::WorkflowStep.list(self) if id
33
32
  @steps ||= []
34
33
  end
35
34
 
@@ -2,7 +2,7 @@ require_relative 'endpoint'
2
2
 
3
3
  module Manifestly
4
4
  module Entity
5
- class WorkflowStep < Base
5
+ class WorkflowStep < ChildEndpoint
6
6
  attr_accessor :id
7
7
  attr_accessor :checklist_id
8
8
  attr_accessor :position
@@ -19,11 +19,29 @@ module Manifestly
19
19
  attr_accessor :late_at_basis
20
20
  attr_accessor :parent_step_id
21
21
 
22
- def initialize(workflow, data = {})
23
- raise 'invalid workflow' unless workflow.is_a?(Workflow)
22
+ invalid_method(:create)
23
+ invalid_class_method(:get)
24
+ invalid_method(:update)
25
+ invalid_method(:save)
26
+ invalid_method(:delete)
24
27
 
25
- @parent = workflow
26
- super(data)
28
+ def self.parent_class
29
+ Workflow
30
+ end
31
+
32
+ def self.endpoint_target
33
+ :steps
34
+ end
35
+
36
+ def content_objects
37
+ return @content_objects if @content_objects
38
+
39
+ @content_objects = Manifestly::Entity::WorkflowStepContentObject.list(self) if id
40
+ @content_objects ||= []
41
+ end
42
+
43
+ def content_objects=(values)
44
+ @content_objects = Array(values).map { |it| WorkflowStepContentObject.new(self, it) }
27
45
  end
28
46
 
29
47
  # Header step needs to always be a boolean (even if not set)
@@ -0,0 +1,21 @@
1
+ require_relative 'endpoint'
2
+
3
+ module Manifestly
4
+ module Entity
5
+ class WorkflowStepContentObject < ChildEndpoint
6
+ attr_accessor :id
7
+ attr_accessor :caption
8
+ attr_accessor :content
9
+ attr_accessor :content_type
10
+ attr_accessor :position
11
+
12
+ def self.parent_class
13
+ WorkflowStep
14
+ end
15
+
16
+ def self.endpoint_target
17
+ :content_objects
18
+ end
19
+ end
20
+ end
21
+ end
@@ -34,6 +34,17 @@ module Manifestly
34
34
  Faraday.post(path, params.to_json, headers)
35
35
  end
36
36
 
37
+ def put(path, params: {}, headers: {})
38
+ handle_request { raw_put("#{url}/#{api_version}/#{path}", params: params, headers: headers) }
39
+ end
40
+
41
+ private def raw_put(path, params: {}, headers: {})
42
+ include_api_key!(params)
43
+ include_json_content_type!(headers)
44
+ include_json_accept!(headers)
45
+ Faraday.put(path, params.to_json, headers)
46
+ end
47
+
37
48
  def delete(path, params: {}, headers: {})
38
49
  handle_request { raw_delete("#{url}/#{api_version}/#{path}", params: params, headers: headers) }
39
50
  end
@@ -1,3 +1,3 @@
1
1
  module Manifestly
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '1.0.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manifestly-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Firespring
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-14 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -62,11 +62,12 @@ files:
62
62
  - lib/manifestly.rb
63
63
  - lib/manifestly/entity/base.rb
64
64
  - lib/manifestly/entity/checklist_run.rb
65
- - lib/manifestly/entity/checklist_step.rb
65
+ - lib/manifestly/entity/checklist_run_step.rb
66
66
  - lib/manifestly/entity/endpoint.rb
67
67
  - lib/manifestly/entity/user.rb
68
68
  - lib/manifestly/entity/workflow.rb
69
69
  - lib/manifestly/entity/workflow_step.rb
70
+ - lib/manifestly/entity/workflow_step_content_object.rb
70
71
  - lib/manifestly/http/client.rb
71
72
  - lib/manifestly/version.rb
72
73
  - manifestly-client.gemspec