Skip to content

Commit

Permalink
File Pushes added
Browse files Browse the repository at this point in the history
some minor fixes for unadjusted types
  • Loading branch information
kariudo committed Feb 3, 2015
1 parent 9d6b1f6 commit 6d5bba2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
A complete go package for interacting with the fantastic Pushbullet service.

## Status
primary feature development still in progress...
primary feature development still in progress, see below for current status:

### Done :
* Get User
Expand All @@ -15,12 +15,13 @@ primary feature development still in progress...
* Link
* Address
* Checklist
* File

### Todo :
* Set User preferences
* Pushes
* ~~Note~~
* ~~Link~~
* ~~Address~~
* ~~Checklist~~
* File
* Devices
* Contacts
* Subscriptions
* Web Sockets
* Upload Requests (upload files)
* OAuth account access
45 changes: 42 additions & 3 deletions gopushbullet.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (c *Client) SendLink(title, body, url string) error {
//SendLinkToTarget sends a link type push to a specific device.
func (c *Client) SendLinkToTarget(targetType, target, title, body, url string) error {
var p = PushMessage{
Type: "note",
Type: "link",
Title: title,
Body: body,
URL: url,
Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *Client) SendAddress(title, name, address string) error {
//SendAddressToTarget sends an address type push to a specific device.
func (c *Client) SendAddressToTarget(targetType, target, title, name, address string) error {
var p = PushMessage{
Type: "note",
Type: "address",
Title: title,
Name: name,
Address: address,
Expand Down Expand Up @@ -276,7 +276,7 @@ func (c *Client) SendChecklist(title string, items []string) error {
//SendChecklistToTarget sends a checklist type push to a specific device.
func (c *Client) SendChecklistToTarget(targetType, target, title string, items []string) error {
var p = PushMessage{
Type: "note",
Type: "checklist",
Title: title,
Items: items,
}
Expand Down Expand Up @@ -304,6 +304,45 @@ func (c *Client) SendChecklistToTarget(targetType, target, title string, items [
return nil
}

//SendFile simply sends a file type push to all of the users devices
func (c *Client) SendFile(title string, items []string) error {
err := c.SendChecklistToTarget("all", "", title, items)
return err
}

//SendFileToTarget sends a file type push to a specific device.
func (c *Client) SendFileToTarget(targetType, target, fileName, fileType, fileURL, body string, items []string) error {
var p = PushMessage{
Type: "file",
FileName: fileName,
FileType: fileType,
FileURL: fileURL,
Body: body,
}
switch targetType {
case "device":
p.DeviceID = target
case "email":
p.Email = target
case "channel":
p.ChannelTag = target
case "client":
p.ClientID = target
default:
// only remaining acceptable type is "all" which takes no addtional fields
if targetType != "all" {
return errors.New("Invalid target type")
}
}

_, apiError, err := c.makeCall("POST", "pushes", p)
if err != nil {
log.Println("Failed to send file:", err, apiError.String())
return err
}
return nil
}

func (c *Client) makeCall(method string, call string, data interface{}) (responseBody []byte, apiError *Error, err error) {
// make sure API key seems ok
if len(c.APIKey) == 0 {
Expand Down

0 comments on commit 6d5bba2

Please sign in to comment.