onesky

package module
v0.0.0-...-2bc5b22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2017 License: GPL-2.0 Imports: 13 Imported by: 0

README

onesky-go

Build Status Code Climate Coverage Status GoDoc License

Go utils for working with OneSky translation service.

Install

$ go get github.com/SebastianCzoch/onesky-go

or via Godep

$ godep get github.com/SebastianCzoch/onesky-go

Examples

Example 1 - Download file
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	fmt.Println(onesky.DownloadFile("filename", "locale"))
}
Example 2 - Upload file
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	_, err := onesky.UploadFile("messages.yml", "YAML", "en-US", true)
	if err != nil {
		fmt.Println("Can not upload file")
	}
}
Example 3 - Delete file
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	err := onesky.DeleteFile("messages.yml")
	if err != nil {
		fmt.Println("Can not delete file")
	}
}
Example 4 - Get informations about uploaded files
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	list, err := onesky.ListFiles(1, 100)
	if err != nil {
		fmt.Println("Can not download list of uploaded files")
	}
	fmt.Println(list)
}
Example 5 - List import tasks
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	list, err := onesky.ImportTasks(map[string]interface{}{
		"per_page": 50,
		"status": "completed", // all, completed, in-progress, failed
	})
	if err != nil {
		fmt.Println("Can not download list of import tasks")
	}
	fmt.Println(list)
}
Example 6 - Show an import task
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	task, err := onesky.ImportTask(773572) // import id
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(task)
}
Example 7 - Get a project's translations status
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	status, err := onesky.GetTranslationsStatus("string.po", "ja-JP")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(status)
}
Example 8 - Get languages
package main

import (
	"fmt"
	"github.com/SebastianCzoch/onesky-go"
)

func main() {
	onesky := onesky.Client{APIKey: "abcdef", Secret: "abcdef", ProjectID: 1}
	languages, err := onesky.GetLanguages()
	if err != nil {
		fmt.Println("Can not get languages")
	}
	fmt.Println(languages)
}

API

(c *Client) DownloadFile(fileName, locale string) (string, error)

Downloads translation file from OneSky.

Returns file content via string.

(c *Client) UploadFile(file, fileFormat, locale string, keepStrings bool) (UploadData, error)

Upload translation file to OneSky.

  • file should be a full path to file
(c *Client) DeleteFile(fileName string) error

Permanently remove file from OneSky service (with translations)!

(c *Client) ListFiles(page, perPage int) ([]FileData, error)

Get informations about files uploaded to OneSky

(c *Client) ImportTasks(params) ([]TaskData, error)

List import tasks. (Default params: {"page": 1, "per_page": 50, "status": "all"})

(c *Client) ImportTask(importID) (TaskData, error)

Show an import task.

(c *Client) GetTranslationsStatus(fileName, locale string) (TranslationsStatus, error)

Shows a project's translations status.

(c *Client) GetLanguages() ([]Language, error)

Get informations about available languages in project

Tests

$ go test ./...

License

GNU v2

Support

Issues for this project should be reported on GitHub issues

Documentation

Overview

Package onesky is go utils for working with OneSky translation service Copyright (c) 2015 Sebastian Czoch <sebastian@czoch.eu>. All rights reserved. Use of this source code is governed by a GNU v2 license found in the LICENSE file.

Index

Constants

View Source
const APIAddress = "https://platform.api.onesky.io"

APIAddress is https address to OneSky API

View Source
const APIVersion = "1"

APIVersion is OneSky API version which will be used

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Secret    string
	APIKey    string
	ProjectID int
}

Client is basics struct for this package contains Secret, APIKey and ProjectID which is needed to authorize in OneSky service

func (*Client) DeleteFile

func (c *Client) DeleteFile(fileName string) error

DeleteFile is method on Client struct which remove file from OneSky service

func (*Client) DownloadFile

func (c *Client) DownloadFile(fileName, locale string) (string, error)

DownloadFile is method on Client struct which download form OneSky service choosen file as string

func (*Client) GetLanguages

func (c *Client) GetLanguages() ([]Language, error)

GetLanguages is method on Client struct which download from OneSky service information about available languages in project

func (*Client) GetTranslationsStatus

func (c *Client) GetTranslationsStatus(fileName, locale string) (TranslationsStatus, error)

GetTranslationsStatus returns information about a project's translation status

func (*Client) ImportTask

func (c *Client) ImportTask(importID int64) (TaskData, error)

ImportTask : Show an import task. Parameters: import_id

func (*Client) ImportTasks

func (c *Client) ImportTasks(params map[string]interface{}) ([]TaskData, error)

ImportTasks : List import tasks. Parameters: page: 1, per_page: 50, status: [all|completed|in-progress|failed] tasks, err := onesky.ImportTasks(map[string]interface{}{"per_page": 50, "status": "in-progress"})

func (*Client) ListFiles

func (c *Client) ListFiles(page, perPage int) ([]FileData, error)

ListFiles is method on Client struct which download form OneSky service informations about uploaded files

func (*Client) UploadFile

func (c *Client) UploadFile(file, fileFormat, locale string, keepStrings bool) (UploadData, error)

UploadFile is method on Client struct which upload file to OneSky service

type FileData

type FileData struct {
	Name                string     `json:"name"`
	FileName            string     `json:"file_name"`
	StringCount         int        `json:"string_count"`
	LastImport          LastImport `json:"last_import"`
	UpoladedAt          string     `json:"uploaded_at"`
	UpoladedAtTimestamp int        `json:"uploaded_at_timestamp"`
}

FileData is a struct which contains informations about file uploaded to OneSky service

type ImportTaskResponse

type ImportTaskResponse struct {
	Data TaskData `json:"data"`
}

ImportTaskResponse is a struct which contains informations about the response from show an import task API

type ImportTasksResponse

type ImportTasksResponse struct {
	Data []TaskData `json:"data"`
}

ImportTasksResponse is a struct which contains informations about the response from list import tasks API

type Language

type Language struct {
	Code                string `json:"code"`
	EnglishName         string `json:"english_name"`
	LocalName           string `json:"local_name"`
	CustomLocale        string `json:"custom_locale"`
	Locale              string `json:"locale"`
	Region              string `json:"region"`
	TranslationProgress string `json:"translation_progress"`
}

Language is a struct which contains informations about locale

type LastImport

type LastImport struct {
	ID     int    `json:"id"`
	Status string `json:"status"`
}

LastImport is a struct which contains informations about last upload

type TaskData

type TaskData struct {
	ID                  int64
	OriginalID          interface{} `json:"id"`
	File                TaskFile    `json:"file"`
	StringCount         int         `json:"string_count"`
	WordCount           int         `json:"word_count"`
	Status              string      `json:"status"`
	CreateddAt          string      `json:"created_at"`
	CreateddAtTimestamp int         `json:"created_at_timestamp"`
}

TaskData is a struct which contains informations about import task

type TaskFile

type TaskFile struct {
	Name   string   `json:"name"`
	Format string   `json:"format"`
	Locale Language `json:"locale"`
}

TaskFile is a struct which contains informations about file of import task

type TranslationsStatus

type TranslationsStatus struct {
	FileName    string   `json:"file_name"`
	Locale      Language `json:"locale"`
	Progress    string   `json:"progress"`
	StringCount int64    `json:"string_count"`
	WordCount   int64    `json:"word_count"`
}

TranslationsStatus is a struct which contains information about a project's translation status

type UploadData

type UploadData struct {
	Name     string   `json:"name"`
	Format   string   `json:"format"`
	Language Language `json:"language"`
	Import   TaskData `json:"import"`
}

UploadData is a struct which contains informations about uploaded file

type UploadResponse

type UploadResponse struct {
	Data UploadData `json:"data"`
}

UploadResponse is a struct which contains informations about the response from upload file API

Directories

Path Synopsis
Godeps
_workspace/src/github.com/jarcoal/httpmock
HTTPmock provides tools for mocking HTTP responses.
HTTPmock provides tools for mocking HTTP responses.
_workspace/src/github.com/stretchr/testify/assert
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL