Skip to content

Commit

Permalink
fix PSR2 standart, add demo bot, add library structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdaan committed Feb 5, 2017
1 parent c182d4c commit fe2dda4
Show file tree
Hide file tree
Showing 21 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.lock
.idea
.DS_STORE
/examples/config.php
.php_cs.cache
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# PHP sdk for Viber api

[![Build
Status](https://secure.travis-ci.org/Bogdaan/Distance.png)](http://travis-ci.org/Bogdaan/viber-bot-php)

Library to develop a bot for the Viber platform. [Create you first Viber bot setp by step](docs/first-steps.md)
See demo at [viber chat](viber://pa?chatURI=viber-bot-php&context=github.com)

## Installation

Expand Down Expand Up @@ -53,6 +57,53 @@ try {

See more in **examples** directory.

## Library structure

```
.
├── Api
│   ├── Entity.php
│   ├── Event # all remote events ("callbacks")
│   │   ├── Conversation.php # fires when user open 1v1 chat
│   │   ├── Delivered.php # fires when message delivered (for each device)
│   │   ├── Factory.php # Event factory
│   │   ├── Failed.php # fires when delivery failed (for each device)
│   │   ├── Message.php # fires when user send message
│   │   ├── Seen.php # fires when user read message (for each device)
│   │   ├── Subscribed.php # fires when user subscribe to PA
│   │   ├── Type.php # available types
│   │   └── Unsubscribed.php # fires when user unsubscribed
│   ├── Event.php # base class for all events
│   ├── Exception #
│   │   └── ApiException.php # remote or logic error
│   ├── Keyboard #
│   │   └── Button.php # all types of buttons here
│   ├── Keyboard.php # button container
│   ├── Message #
│   │   ├── Contact.php #
│   │   ├── Factory.php #
│   │   ├── File.php #
│   │   ├── Location.php #
│   │   ├── Picture.php #
│   │   ├── Sticker.php #
│   │   ├── Text.php #
│   │   ├── Type.php # available message types
│   │   ├── Url.php #
│   │   └── Video.php #
│   ├── Message.php # base class for all messages
│   ├── Response.php # wrap api response
│   ├── Sender.php # represent bot-sender
│   ├── Signature.php # signature helper (verify or create sign)
│   ├── User #
│   │   └── State.php # user state (online/offline etc)
│   └── User.php # viber user
├── Bot #
│   └── Manager.php # manage bot closures
├── Bot.php # bot class
└── Client.php # api client
```


## Read more

- [Create you first Viber bot](docs/first-steps.md)
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function toApiArray()
foreach ($entity as $name => &$value) {
if (is_null($value)) {
unset($entity[$name]);
} else if ($value instanceof Entity) {
} elseif ($value instanceof Entity) {
$value = $value->toArray();
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Api/Event/Delivered.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function getUserId()
{
return $this->user_id;
}

}
2 changes: 0 additions & 2 deletions src/Api/Event/Failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ public function getDsc()
{
return $this->dsc;
}


}
1 change: 0 additions & 1 deletion src/Api/Event/Seen.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ public function getUserId()
{
return $this->user_id;
}

}
3 changes: 1 addition & 2 deletions src/Api/Event/Subscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ class Subscribed extends Event
protected $user;

/**
* Get the value of Viber user
* Get the value of Viber user
*
* @return \Viber\Api\User
*/
public function getUser()
{
return $this->user;
}

}
1 change: 0 additions & 1 deletion src/Api/Event/Unsubscribed.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ public function getUserId()
{
return $this->user_id;
}

}
1 change: 0 additions & 1 deletion src/Api/Keyboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,4 @@ public function setDefaultHeight($DefaultHeight)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,4 @@ public function setKeyboard(\Viber\Api\Keyboard $keyboard)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,4 @@ public function setPhoneNumber($phone_number)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,4 @@ public function setFileName($file_name)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/Picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,4 @@ public function setThumbnail($thumbnail)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/Sticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@ public function setStickerId($sticker_id)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ public function setText($text)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ public function setMedia($media)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Message/Video.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,4 @@ public function setThumbnail($thumbnail)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Viber\Api\Exception\ApiException;


/**
* Manage backend response, translate api error ot exception
*
Expand Down
1 change: 0 additions & 1 deletion src/Api/Sender.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,4 @@ public function setAvatar($avatar)

return $this;
}

}
1 change: 0 additions & 1 deletion src/Api/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,5 +220,4 @@ public function getMnc()
{
return $this->mnc;
}

}
2 changes: 1 addition & 1 deletion src/Bot.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function onSubscribe(\Closure $handler)
*/
public function onConversation(\Closure $handler)
{
$this->managers[] = new Manager(function(Event $event) {
$this->managers[] = new Manager(function (Event $event) {
return ($event instanceof \Viber\Api\Event\Conversation);
}, $handler);
return $this;
Expand Down

0 comments on commit fe2dda4

Please sign in to comment.