monday_ruby 0.1.0 → 0.3.0

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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.env +1 -0
  3. data/.rubocop.yml +5 -1
  4. data/CHANGELOG.md +19 -0
  5. data/README.md +37 -2
  6. data/docs/README.md +13 -0
  7. data/docs/SUMMARY.md +40 -0
  8. data/docs/client.md +15 -0
  9. data/docs/configuration.md +40 -0
  10. data/docs/error-handling.md +71 -0
  11. data/docs/getting-started.md +25 -0
  12. data/docs/quick-start.md +269 -0
  13. data/docs/resources/README.md +27 -0
  14. data/docs/resources/account/README.md +9 -0
  15. data/docs/resources/account/accounts.md +82 -0
  16. data/docs/resources/activity-log/README.md +9 -0
  17. data/docs/resources/activity-log/activity_logs.md +95 -0
  18. data/docs/resources/board/README.md +21 -0
  19. data/docs/resources/board/archive_board.md +79 -0
  20. data/docs/resources/board/boards.md +96 -0
  21. data/docs/resources/board/create_board.md +95 -0
  22. data/docs/resources/board/delete_board.md +79 -0
  23. data/docs/resources/board/delete_board_subscribers.md +87 -0
  24. data/docs/resources/board/duplicate_board.md +94 -0
  25. data/docs/resources/board/update_board.md +91 -0
  26. data/docs/resources/board-view/README.md +9 -0
  27. data/docs/resources/board-view/board_views.md +88 -0
  28. data/docs/resources/column/README.md +25 -0
  29. data/docs/resources/column/change_column_metadata.md +70 -0
  30. data/docs/resources/column/change_column_title.md +68 -0
  31. data/docs/resources/column/change_column_value.md +73 -0
  32. data/docs/resources/column/change_multiple_column_value.md +81 -0
  33. data/docs/resources/column/change_simple_column_value.md +69 -0
  34. data/docs/resources/column/column_values.md +115 -0
  35. data/docs/resources/column/columns.md +117 -0
  36. data/docs/resources/column/create_column.md +70 -0
  37. data/docs/resources/column/delete_column.md +58 -0
  38. data/docs/resources/item/README.md +17 -0
  39. data/docs/resources/item/archive_item.md +80 -0
  40. data/docs/resources/item/create_item.md +105 -0
  41. data/docs/resources/item/delete_item.md +80 -0
  42. data/docs/resources/item/duplicate_item.md +87 -0
  43. data/docs/resources/item/items.md +95 -0
  44. data/docs/response.md +21 -0
  45. data/lib/monday/client.rb +38 -10
  46. data/lib/monday/configuration.rb +11 -1
  47. data/lib/monday/error.rb +92 -0
  48. data/lib/monday/response.rb +4 -1
  49. data/lib/monday/util.rb +30 -0
  50. data/lib/monday/version.rb +1 -1
  51. data/lib/monday_ruby.rb +13 -0
  52. data/monday_ruby.gemspec +2 -2
  53. metadata +45 -4
@@ -0,0 +1,87 @@
1
+ # #duplicate\_item
2
+
3
+ The `duplicate_item` mutation will allow you to duplicate an item.
4
+
5
+ ### Basic usage
6
+
7
+ This method accepts three required arguments - `board_id`, `item_id` and `with_updates`.
8
+
9
+ {% code lineNumbers="true" %}
10
+ ```ruby
11
+ client = Monday::Client.new(token: <AUTH_TOKEN>)
12
+
13
+ board_id = "123"
14
+ item_id = "7890"
15
+ with_updates = true
16
+ response = client.duplicate_item(board_id, item_id, with_updates)
17
+
18
+ puts response.body
19
+ ```
20
+ {% endcode %}
21
+
22
+ This will return the items' ID, name and created\_at fields by default.
23
+
24
+ The response body from the above query would be as follows:
25
+
26
+ {% code lineNumbers="true" %}
27
+ ```json
28
+ {
29
+ "data": {
30
+ "duplicate_item": {
31
+ "id": "0123",
32
+ "name": "New Task (copy)",
33
+ "created_at": "2023-06-27T16:45:07Z"
34
+ }
35
+ },
36
+ "account_id": 123
37
+ }
38
+ ```
39
+ {% endcode %}
40
+
41
+ ### Customizing fields to retrieve
42
+
43
+ You can customize the fields to retrieve by passing in the `select` option and listing all the fields you need to retrieve as an array.
44
+
45
+ {% code lineNumbers="true" %}
46
+ ```ruby
47
+ client = Monday::Client.new(token: <AUTH_TOKEN>)
48
+
49
+ board_id = "123"
50
+ item_id = "7890"
51
+ with_updates = true
52
+
53
+ select = %w[id state creator_id]
54
+ response = client.duplicate_item(board_id, item_id, with_updates, select: select)
55
+
56
+ puts response.body
57
+ ```
58
+ {% endcode %}
59
+
60
+ ### Retrieving nested fields
61
+
62
+ Some fields have nested attributes, and you need to specify the attributes to retrieve that field; else, the API will respond with an error. For example, the field `creator` is of type `User` and expects you to pass the attributes from `User` that you want to retrieve for `creator`.
63
+
64
+ {% code lineNumbers="true" %}
65
+ ```ruby
66
+ client = Monday::Client.new(token: <AUTH_TOKEN>)
67
+
68
+ board_id = "123"
69
+ item_id = "7890"
70
+ with_updates = true
71
+
72
+ select = [
73
+ "id",
74
+ "state",
75
+ "creator_id",
76
+ {
77
+ creator: %w[id name email is_admin]
78
+ }
79
+ ]
80
+
81
+ response = client.duplicate_item(board_id, item_id, with_updates, select: select)
82
+
83
+ puts response.body
84
+ ```
85
+ {% endcode %}
86
+
87
+ You can find the list of all the available fields for items [here](https://developer.monday.com/api-reference/docs/items#fields).
@@ -0,0 +1,95 @@
1
+ # #items
2
+
3
+ Querying `items` will return the metadata for one or a collection of columns.
4
+
5
+ ### Basic usage
6
+
7
+ This method accepts various arguments to fetch the items. You can find the complete list of arguments [here](https://developer.monday.com/api-reference/docs/items#arguments).
8
+
9
+ You can pass these filters using the `args` option.
10
+
11
+ {% code lineNumbers="true" %}
12
+ ```ruby
13
+ client = Monday::Client.new(token: <AUTH_TOKEN>)
14
+
15
+ args = {
16
+ ids: [1234, 5678]
17
+ }
18
+ response = client.items(args: args)
19
+
20
+ puts response.body
21
+ ```
22
+ {% endcode %}
23
+
24
+ This will return the items' ID, name and created\_at fields by default.
25
+
26
+ The response body from the above query would be as follows:
27
+
28
+ {% code lineNumbers="true" %}
29
+ ```json
30
+ {
31
+ "data": {
32
+ "items": [
33
+ {
34
+ "id": "1234",
35
+ "name": "Task 1",
36
+ "created_at": "2023-06-26T23:20:56Z"
37
+ },
38
+ "items": [
39
+ {
40
+ "id": "5678",
41
+ "name": "Task 2",
42
+ "created_at": "2023-06-26T23:25:50Z"
43
+ }
44
+ ]
45
+ },
46
+ "account_id": 123
47
+ }
48
+ ```
49
+ {% endcode %}
50
+
51
+ ### Customizing fields to retrieve
52
+
53
+ You can customize the fields to retrieve by passing in the `select` option and listing all the fields you need to retrieve as an array.
54
+
55
+ {% code lineNumbers="true" %}
56
+ ```ruby
57
+ client = Monday::Client.new(token: <AUTH_TOKEN>)
58
+
59
+ args = {
60
+ ids: [1234, 5678]
61
+ }
62
+ select = %w[id state creator_id]
63
+ response = client.items(args: args, select: select)
64
+
65
+ puts response.body
66
+ ```
67
+ {% endcode %}
68
+
69
+ ### Retrieving nested fields
70
+
71
+ Some fields have nested attributes, and you need to specify the attributes to retrieve that field; else, the API will respond with an error. For example, the field `creator` is of type `User` and expects you to pass the attributes from `User` that you want to retrieve for `creator`.
72
+
73
+ {% code lineNumbers="true" %}
74
+ ```ruby
75
+ client = Monday::Client.new(token: <AUTH_TOKEN>)
76
+
77
+ args = {
78
+ ids: [1234, 5678]
79
+ }
80
+ select = [
81
+ "id",
82
+ "state",
83
+ "creator_id",
84
+ {
85
+ creator: %w[id name email is_admin]
86
+ }
87
+ ]
88
+
89
+ response = client.items(args: args, select: select)
90
+
91
+ puts response.body
92
+ ```
93
+ {% endcode %}
94
+
95
+ You can find the list of all the available fields for items [here](https://developer.monday.com/api-reference/docs/items#fields).
data/docs/response.md ADDED
@@ -0,0 +1,21 @@
1
+ # Response
2
+
3
+ Every request made using the client will return a `Monday::Response` object. This object consists of the following methods:
4
+
5
+ #### `status`
6
+
7
+ This is the returned HTTP status code.
8
+
9
+ #### `body`
10
+
11
+ This is the response body.
12
+
13
+ #### `headers`
14
+
15
+ This is the response header.
16
+
17
+ #### `success?`
18
+
19
+ This returns true or false based on the status code and the response body.
20
+
21
+ Sometimes when the application handles the exceptions, the API will return a `200` status code, but the body will return the error message.
data/lib/monday/client.rb CHANGED
@@ -9,9 +9,10 @@ require_relative "request"
9
9
  require_relative "response"
10
10
  require_relative "resources"
11
11
  require_relative "util"
12
+ require_relative "error"
12
13
 
13
14
  module Monday
14
- # Client executes requests against the Monday.com API and
15
+ # Client executes requests against the monday.com's API and
15
16
  # allows a user to mutate and retrieve resources.
16
17
  class Client
17
18
  include Resources
@@ -19,19 +20,20 @@ module Monday
19
20
  JSON_CONTENT_TYPE = "application/json"
20
21
  private_constant :JSON_CONTENT_TYPE
21
22
 
22
- Monday::Configuration::CONFIGURATION_FIELDS.each do |config_key|
23
- define_method(config_key) do
24
- @config.public_send(config_key)
25
- end
26
- end
23
+ attr_reader :config
27
24
 
28
25
  def initialize(config_args = {})
29
- @config = Monday::Configuration.new(**config_args)
30
- yield(@config) if block_given?
26
+ @config = config_options(config_args)
31
27
  end
32
28
 
33
29
  private
34
30
 
31
+ def config_options(config_args)
32
+ return Monday.config if config_args.empty?
33
+
34
+ Configuration.new(**config_args)
35
+ end
36
+
35
37
  def uri
36
38
  URI(@config.host)
37
39
  end
@@ -44,8 +46,34 @@ module Monday
44
46
  end
45
47
 
46
48
  def make_request(body)
47
- response = Monday::Request.post(uri, body, request_headers)
48
- Monday::Response.new(response)
49
+ response = Request.post(uri, body, request_headers)
50
+
51
+ handle_response(Response.new(response))
52
+ end
53
+
54
+ def handle_response(response)
55
+ return response if response.success?
56
+
57
+ raise_errors(response)
58
+ end
59
+
60
+ def raise_errors(response)
61
+ raise default_exception(response) unless (200..299).cover?(response.status)
62
+
63
+ raise response_exception(response)
64
+ end
65
+
66
+ def response_exception(response)
67
+ error_code = response.body["error_code"]
68
+
69
+ return Error.new(response: response) if error_code.nil?
70
+
71
+ exception_klass, code = Util.response_error_exceptions_mapping(error_code)
72
+ exception_klass.new(message: error_code, response: response, code: code)
73
+ end
74
+
75
+ def default_exception(response)
76
+ Util.status_code_exceptions_mapping(response.status).new(response: response)
49
77
  end
50
78
  end
51
79
  end
@@ -9,11 +9,13 @@ module Monday
9
9
  # host: defaults to https://api.monday.com/v2
10
10
  class Configuration
11
11
  DEFAULT_HOST = "https://api.monday.com/v2"
12
- private_constant :DEFAULT_HOST
12
+ DEFAULT_TOKEN = nil
13
+ DEFAULT_VERSION = "2023-07"
13
14
 
14
15
  CONFIGURATION_FIELDS = %i[
15
16
  token
16
17
  host
18
+ version
17
19
  ].freeze
18
20
 
19
21
  attr_accessor(*CONFIGURATION_FIELDS)
@@ -23,10 +25,18 @@ module Monday
23
25
  raise ArgumentError, "Unknown arguments: #{invalid_keys}" unless invalid_keys.empty?
24
26
 
25
27
  @host = DEFAULT_HOST
28
+ @token = DEFAULT_TOKEN
29
+ @version = DEFAULT_VERSION
26
30
 
27
31
  config_args.each do |key, value|
28
32
  public_send("#{key}=", value)
29
33
  end
30
34
  end
35
+
36
+ def reset
37
+ @token = DEFAULT_TOKEN
38
+ @host = DEFAULT_HOST
39
+ @version = DEFAULT_VERSION
40
+ end
31
41
  end
32
42
  end
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Monday
4
+ # Monday::Error is the base error class from which other
5
+ # specific error classes are derived.
6
+ class Error < StandardError
7
+ attr_reader :response, :message, :code
8
+
9
+ def initialize(message: nil, response: nil, code: nil)
10
+ @response = response
11
+ @message = error_message(message)
12
+ @code = error_code(code)
13
+
14
+ super(@message)
15
+ end
16
+
17
+ def error_data
18
+ return {} if response&.body&.dig("error_data").nil?
19
+
20
+ response.body["error_data"]
21
+ end
22
+
23
+ private
24
+
25
+ def error_code(code)
26
+ return code unless code.nil?
27
+
28
+ response_error_code.nil? ? response&.status : response_error_code
29
+ end
30
+
31
+ def error_message(message)
32
+ return response_error_message if message.nil?
33
+ return message if response_error_message.nil?
34
+
35
+ "#{message}: #{response_error_message}"
36
+ end
37
+
38
+ def response_error_code
39
+ return if response.nil?
40
+
41
+ response.body["status_code"]
42
+ end
43
+
44
+ def response_error_message
45
+ return if response.nil?
46
+
47
+ response.body["error_message"].nil? ? response.body["errors"].to_s : response.body["error_message"].to_s
48
+ end
49
+ end
50
+
51
+ # InternalServerError is raised when the request returns
52
+ # a 500 status code.
53
+ class InternalServerError < Error
54
+ end
55
+
56
+ # AuthorizationError is raised when the request returns
57
+ # a 401 or 403 status code.
58
+ #
59
+ # It is also raised when the body returns the following error_code:
60
+ # UserUnauthorizedException
61
+ class AuthorizationError < Error
62
+ end
63
+
64
+ # RateLimitError is raised when the request returns
65
+ # a 429 status code.
66
+ class RateLimitError < Error
67
+ end
68
+
69
+ # ResourceNotFoundError is raised when the request returns
70
+ # a 404 status code.
71
+ #
72
+ # It is also raised when the body returns the following error_code:
73
+ # ResourceNotFoundException
74
+ class ResourceNotFoundError < Error
75
+ end
76
+
77
+ # ResourceNotFoundError is raised when the request returns
78
+ # a 400 status code.
79
+ #
80
+ # It is also raised when the body returns the following error_codes:
81
+ # InvalidUserIdException, InvalidVersionException, InvalidColumnIdException
82
+ # InvalidItemIdException, InvalidBoardIdException, InvalidArgumentException
83
+ # CreateBoardException, ItemsLimitationException, ItemNameTooLongException
84
+ # ColumnValueException, CorrectedValueException
85
+ class InvalidRequestError < Error
86
+ end
87
+
88
+ # ComplexityError is raised when the body returns the following error_code:
89
+ # ComplexityException
90
+ class ComplexityError < Error
91
+ end
92
+ end
@@ -6,6 +6,9 @@ module Monday
6
6
  #
7
7
  # Returns status code, parsed body and headers.
8
8
  class Response
9
+ ERROR_OBJECT_KEYS = %w[errors error_code error_message].freeze
10
+ private_constant :ERROR_OBJECT_KEYS
11
+
9
12
  attr_reader :status, :body, :headers
10
13
 
11
14
  def initialize(response)
@@ -26,7 +29,7 @@ module Monday
26
29
  attr_reader :response
27
30
 
28
31
  def errors?
29
- parse_body.key?("errors") || parse_body.key?("error_message")
32
+ (parse_body.keys & ERROR_OBJECT_KEYS).any?
30
33
  end
31
34
 
32
35
  def parse_body
data/lib/monday/util.rb CHANGED
@@ -25,6 +25,36 @@ module Monday
25
25
  values
26
26
  end
27
27
 
28
+ def status_code_exceptions_mapping(status_code)
29
+ {
30
+ "500" => InternalServerError,
31
+ "429" => RateLimitError,
32
+ "404" => ResourceNotFoundError,
33
+ "403" => AuthorizationError,
34
+ "401" => AuthorizationError,
35
+ "400" => InvalidRequestError
36
+ }[status_code.to_s] || Error
37
+ end
38
+
39
+ def response_error_exceptions_mapping(error_code)
40
+ {
41
+ "ComplexityException" => [ComplexityError, 429],
42
+ "UserUnauthorizedException" => [AuthorizationError, 403],
43
+ "ResourceNotFoundException" => [ResourceNotFoundError, 404],
44
+ "InvalidUserIdException" => [InvalidRequestError, 400],
45
+ "InvalidVersionException" => [InvalidRequestError, 400],
46
+ "InvalidColumnIdException" => [InvalidRequestError, 400],
47
+ "InvalidItemIdException" => [InvalidRequestError, 400],
48
+ "InvalidBoardIdException" => [InvalidRequestError, 400],
49
+ "InvalidArgumentException" => [InvalidRequestError, 400],
50
+ "CreateBoardException" => [InvalidRequestError, 400],
51
+ "ItemsLimitationException" => [InvalidRequestError, 400],
52
+ "ItemNameTooLongException" => [InvalidRequestError, 400],
53
+ "ColumnValueException" => [InvalidRequestError, 400],
54
+ "CorrectedValueException" => [InvalidRequestError, 400]
55
+ }[error_code] || [Error, 400]
56
+ end
57
+
28
58
  private
29
59
 
30
60
  def format_array(array)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Monday
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/monday_ruby.rb CHANGED
@@ -2,3 +2,16 @@
2
2
 
3
3
  require_relative "monday/client"
4
4
  require_relative "monday/version"
5
+
6
+ # Module to configure the library globally
7
+ module Monday
8
+ module_function
9
+
10
+ def configure
11
+ yield config
12
+ end
13
+
14
+ def config
15
+ @config ||= Configuration.new
16
+ end
17
+ end
data/monday_ruby.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
15
15
  spec.description = "A Gem to easily interact with monday.com API using native Ruby"
16
16
  spec.homepage = repository
17
17
  spec.license = "MIT"
18
- spec.required_ruby_version = ">= 2.6.0"
18
+ spec.required_ruby_version = ">= 2.7.0"
19
19
 
20
20
  spec.metadata = {
21
21
  "homepage_uri" => spec.homepage,
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.files = Dir.chdir(__dir__) do
28
28
  `git ls-files -z`.split("\x0").reject do |f|
29
29
  (File.expand_path(f) == __FILE__) ||
30
- f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
30
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git Gemfile])
31
31
  end
32
32
  end
33
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monday_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sanif Himani
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-28 00:00:00.000000000 Z
11
+ date: 2023-07-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Gem to easily interact with monday.com API using native Ruby
14
14
  email:
@@ -17,6 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - ".env"
20
21
  - ".rspec"
21
22
  - ".rubocop.yml"
22
23
  - ".vscode/settings.json"
@@ -25,8 +26,48 @@ files:
25
26
  - LICENSE
26
27
  - README.md
27
28
  - Rakefile
29
+ - docs/README.md
30
+ - docs/SUMMARY.md
31
+ - docs/client.md
32
+ - docs/configuration.md
33
+ - docs/error-handling.md
34
+ - docs/getting-started.md
35
+ - docs/quick-start.md
36
+ - docs/resources/README.md
37
+ - docs/resources/account/README.md
38
+ - docs/resources/account/accounts.md
39
+ - docs/resources/activity-log/README.md
40
+ - docs/resources/activity-log/activity_logs.md
41
+ - docs/resources/board-view/README.md
42
+ - docs/resources/board-view/board_views.md
43
+ - docs/resources/board/README.md
44
+ - docs/resources/board/archive_board.md
45
+ - docs/resources/board/boards.md
46
+ - docs/resources/board/create_board.md
47
+ - docs/resources/board/delete_board.md
48
+ - docs/resources/board/delete_board_subscribers.md
49
+ - docs/resources/board/duplicate_board.md
50
+ - docs/resources/board/update_board.md
51
+ - docs/resources/column/README.md
52
+ - docs/resources/column/change_column_metadata.md
53
+ - docs/resources/column/change_column_title.md
54
+ - docs/resources/column/change_column_value.md
55
+ - docs/resources/column/change_multiple_column_value.md
56
+ - docs/resources/column/change_simple_column_value.md
57
+ - docs/resources/column/column_values.md
58
+ - docs/resources/column/columns.md
59
+ - docs/resources/column/create_column.md
60
+ - docs/resources/column/delete_column.md
61
+ - docs/resources/item/README.md
62
+ - docs/resources/item/archive_item.md
63
+ - docs/resources/item/create_item.md
64
+ - docs/resources/item/delete_item.md
65
+ - docs/resources/item/duplicate_item.md
66
+ - docs/resources/item/items.md
67
+ - docs/response.md
28
68
  - lib/monday/client.rb
29
69
  - lib/monday/configuration.rb
70
+ - lib/monday/error.rb
30
71
  - lib/monday/request.rb
31
72
  - lib/monday/resources.rb
32
73
  - lib/monday/resources/account.rb
@@ -46,7 +87,7 @@ licenses:
46
87
  metadata:
47
88
  homepage_uri: https://github.com/sanifhimani/monday_ruby
48
89
  documentation_uri: https://monday-ruby.gitbook.io/docs/
49
- changelog_uri: https://github.com/sanifhimani/monday_ruby/blob/v0.1.0/CHANGELOG.md
90
+ changelog_uri: https://github.com/sanifhimani/monday_ruby/blob/v0.3.0/CHANGELOG.md
50
91
  rubygems_mfa_required: 'true'
51
92
  post_install_message:
52
93
  rdoc_options: []
@@ -56,7 +97,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
56
97
  requirements:
57
98
  - - ">="
58
99
  - !ruby/object:Gem::Version
59
- version: 2.6.0
100
+ version: 2.7.0
60
101
  required_rubygems_version: !ruby/object:Gem::Requirement
61
102
  requirements:
62
103
  - - ">="