Skip to content

Commit

Permalink
ServiceCollection save method retuns false or an array of updated data.
Browse files Browse the repository at this point in the history
Added documentation.
  • Loading branch information
Edujugon committed Apr 19, 2017
1 parent 5046a1c commit a99e6ab
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 5 deletions.
58 changes: 55 additions & 3 deletions docs/API-Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,16 @@ Laravel Google Ads Package API Documentation
- [orderBy](https://edujugon.github.io/laravel-google-ads/API-Documentation#serviceorderby)
- [get](https://edujugon.github.io/laravel-google-ads/API-Documentation#serviceget)
- [getService](https://edujugon.github.io/laravel-google-ads/API-Documentation#servicegetservice)

- [where](https://edujugon.github.io/laravel-google-ads/API-Documentation#servicewhere)

### ServiceCollection
> After calling the `get` service method you are getting a serviceCollection
- [where](https://edujugon.github.io/laravel-google-ads/API-Documentation#servicecollectionwhere)
- [set](https://edujugon.github.io/laravel-google-ads/API-Documentation#servicecollectionset)
- [save](https://edujugon.github.io/laravel-google-ads/API-Documentation#servicecollectionsave)
- [items](https://edujugon.github.io/laravel-google-ads/API-Documentation#servicecollectionitems)

### Reports

- [report](https://edujugon.github.io/laravel-google-ads/API-Documentation#report)
Expand Down Expand Up @@ -202,7 +211,7 @@ Edujugon\GoogleAds\Services\Service object orderBy($field)

##### service/get

`get` method gets the entries of the query as a collection.
`get` method gets the entries of the query as a ServiceCollection.

Optional:

Expand All @@ -211,7 +220,7 @@ Optional:
**Syntax**

```php
Illuminate\Support\Collection object get($fields = [])
Edujugon\GoogleAds\Services\ServiceCollection object get($fields = [])
```

##### service/getService
Expand All @@ -224,6 +233,49 @@ Illuminate\Support\Collection object get($fields = [])
Edujugon\GoogleAds\Services\Service object getService()
```

### ServiceCollection

#### servicecollection/where

`where` method filters the list matching the field with the passed value.
You can do the opposite matching passing `true` as third parameter.

**Syntax**

```php
Edujugon\GoogleAds\Services\ServiceCollection object where($field, $value,$opposite = false)
```

#### servicecollection/set

`set` method updates all items of the list the passed field with the passed value.

**Syntax**

```php
Edujugon\GoogleAds\Services\ServiceCollection object set($field, $value)
```

#### servicecollection/save

`save` method persists the data of list items in google.

**Syntax**

```php
false | array save()
```

#### servicecollection/items

`items` method gets the items as Illuminate collection.

**Syntax**

```php
Illuminate\Support\Collection object items()
```

### Reports

#### report
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ Finally you can persist those changes with the `save` method:
$campaign = $campaign->save();
```

Save method returns an array of updated elements or false if nothing updated.

> Important!! notice that it will persist all elements that matched in where condition.
### Google Reports
Expand Down
11 changes: 10 additions & 1 deletion src/Services/ServiceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ public function save()
if(empty($operations))
return false;

return $this->adWordsServices->mutate($operations);
return $this->adWordsServices->mutate($operations)->getValue();
}

/**
* Get item list.
* @return Collection
*/
public function items()
{
return $this->items;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ServicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function update_campaign_name()

if($changed)
{
$this->assertInstanceOf(\Google\AdsApi\AdWords\v201702\cm\CampaignReturnValue::class,$changed);
$this->assertInternalType('array',$changed);

$this->assertEquals('hello !!',$changed->getValue()[0]->getName());
}
Expand Down

0 comments on commit a99e6ab

Please sign in to comment.