Skip to content

Commit

Permalink
Merge pull request #6 from gponty/version202310
Browse files Browse the repository at this point in the history
Passage à la version 2023-10
  • Loading branch information
gponty authored Nov 28, 2023
2 parents 9fa55ad + 8454f62 commit e311755
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 28 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Symfony Monday Api

This is a Symfony 6 Bundle helps you to use monday API v2 : https://developer.monday.com/apps/docs/mondayapi.
It use version 2023-10.

## Installation

Expand All @@ -14,7 +15,6 @@ This is a Symfony 6 Bundle helps you to use monday API v2 : https://developer.mo

``` shell
MONDAY_API_KEY=your_token
MONDAY_API_VERSION=2023-07

```

Expand All @@ -23,7 +23,6 @@ This is a Symfony 6 Bundle helps you to use monday API v2 : https://developer.mo
``` shell
monday:
api_key: '%env(MONDAY_API_KEY)%'
api_version: '%env(MONDAY_API_VERSION)%'
```


Expand All @@ -46,10 +45,12 @@ Use the service :
groups {
id
title
items(limit: 100, page:1) {
id
name
}
items_page(limit: 100, page:1) {
cursor
items{
id
name
}
}
}
}';
Expand Down
38 changes: 18 additions & 20 deletions src/MondayApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MondayApi
{
public function __construct(private readonly string $mondayApiKey, private readonly string $mondayApiVersion)
public function __construct(private readonly string $mondayApiKey)
{
}

Expand All @@ -22,7 +22,7 @@ public function request(string $query, array $variables = []): bool|array
$headers = [
'Content-Type: application/json',
'User-Agent: Github.com/symfony-monday-api',
'API-Version: '.$this->mondayApiVersion,
'API-Version: 2023-10',
'Authorization: '.$this->mondayApiKey,
];

Expand Down Expand Up @@ -110,7 +110,7 @@ public function createGroup(int $boardId, string $groupTitle): string|bool
}

/**
* Create new item if not exists.
* Create new item if not exists, key is column name.
*
* @param int $boardId Monday board id
* @param string $groupId Monday group id
Expand All @@ -122,15 +122,21 @@ public function createGroup(int $boardId, string $groupTitle): string|bool
public function createItem(int $boardId, string $groupId, string $itemName, array $itemValues): string|bool
{
// On insere ou update dans Monday
// On recuperer tous les items et groupes pour checker que l'item existe ou pas
// On check si l'item existe ou pas
$query = '{
boards(ids: '.$boardId.') {
id
name
groups(ids: '.$groupId.') {
groups(ids: "'.$groupId.'") {
id
title
items {id name}
items_page(query_params: {rules: [{column_id: "name", compare_value: ["'.$itemName.'"]}], operator: and}){
cursor
items {
id
name
}
}
}
}
}
Expand All @@ -139,25 +145,15 @@ public function createItem(int $boardId, string $groupId, string $itemName, arra
if (false === $responseContent) {
return false;
}
if (!isset($responseContent['boards'][0]['groups'][0]['items']) || !\is_array($responseContent['boards'][0]['groups'][0]['items'])) {
if (!isset($responseContent['boards'][0]['groups'][0]['items_page']['items']) || !\is_array($responseContent['boards'][0]['groups'][0]['items_page']['items'])) {
return false;
}
$items = $responseContent['boards'][0]['groups'][0]['items'];
$items = $responseContent['boards'][0]['groups'][0]['items_page']['items'];

// On créé les domaines qui n'existent pas
// On créé les items qui n'existent pas
// et on met à jour ceux qui existent
$trouve = false;
$itemId = 0;

foreach ($items as $item) {
if ($item['name'] === $itemName) {
$trouve = true;
$itemId = $item['id'];
break;
}
}

if (!$trouve) {
if (\count($items) === 0) {
$query = 'mutation {
create_item(board_id: '.$boardId.', group_id: "'.$groupId.'", item_name: "'.$itemName.'") {
id
Expand All @@ -172,6 +168,8 @@ public function createItem(int $boardId, string $groupId, string $itemName, arra
return false;
}
$itemId = $data['create_item']['id'];
} else {
$itemId = $items[0]['id'];
}

// On met à jour
Expand Down
2 changes: 0 additions & 2 deletions src/MondayBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
$container->services()
->get(MondayApi::class)
->arg('$mondayApiKey', $config['api_key'])
->arg('$mondayApiVersion', $config['api_version'])
;
}

Expand All @@ -26,7 +25,6 @@ public function configure(DefinitionConfigurator $definition): void
$definition->rootNode()
->children()
->scalarNode('api_key')->defaultValue('%env(MONDAY_API_KEY)%')->end()
->scalarNode('api_version')->defaultValue('%env(MONDAY_API_VERSION)%')->end()
->end()
;
}
Expand Down

0 comments on commit e311755

Please sign in to comment.