Unofficial Sift Science API (Golang client)
Things that are done/supported and those that yet need to be supported
- Events API
- Label API
- Score API
- Device Fingerprinting API
Installation for this package should be straight forward.
go get github.com/0x19/sift-golangOnce it's installed you can import it as
import (
"github.com/0x19/sift-golang"
)Bellow you can find few examples on how to use sift-golang.
Here's an example that sends a $transaction event to sift.
package main
import (
"log"
"github.com/0x19/sift-golang"
)
func main() {
s := sift.New("your_api_key")
// Name of the event. Can be pre-defined such as $transaction and custom
// such as "my_custom_event"
eventName := "$transaction"
data := map[string]interface{}{
"$user_id": "someone@someone.com",
"$transaction_id": "1233456",
"$currency_code": "USD",
"$amount": 15230000,
"$time": 1327604222,
"trip_time": 930,
"distance_traveled": 5.26,
"$order_id": "ORDER-123124124",
}
extras := map[string]interface{}{
"return_action": true,
}
r, err := s.Track(eventName, data, extras)
if err != nil {
log.Fatal(err)
}
log.Printf("Got tracking record: %v", r)
}package main
import (
"log"
"github.com/0x19/sift-golang"
)
func main() {
s := sift.New("your_api_key")
record, err := s.Label("some-user-id", map[string]interface{}{
"$is_bad": true,
"$reasons": []string{"$chargeback", "$fraud"},
"$description": "Some description about this user...",
})
if err != nil {
log.Fatal(err)
}
log.Printf("Got label record: %v", record)
}package main
import (
"log"
"github.com/0x19/sift-golang"
)
func main() {
s := sift.New("your_api_key")
response, err := s.UnLabel("some-user-id")
if err != nil {
log.Fatal(err)
}
log.Printf("Got un-label response: %v", response)
}package main
import (
"log"
"github.com/0x19/sift-golang"
)
func main() {
s := sift.New("your_api_key")
record, err := s.Score("some-user-id")
if err != nil {
log.Fatal(err)
}
log.Printf("Got score response: %v", record.Score)
}Please make sure to read Contribution Guide if you are interested into code contributions :)
(The MIT License)
Copyright (c) 2016 Nevio Vesic, http://www.neviovesic.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.