Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/news websocket client #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/** -diff
vendor/** -diff
*.txz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: goreleaser

on:
pull_request:
push:

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,10 @@

# Dependency directories (remove the comment below to include it)
# vendor/

# Other
*.DS_Store
.cover/
.idea/
dist/
build/
36 changes: 36 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
project_name: benzinga
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- 386
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
21 changes: 21 additions & 0 deletions benzinga/client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package benzinga

import "net/http"

const (
DefaultHostname = "api.benzinga.com"
)

type Client struct {
c *http.Client
}

func NewClient(httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}

return &Client{
c: httpClient,
}
}
7 changes: 7 additions & 0 deletions benzinga/news.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package benzinga

import "github.com/Benzinga/sdk-go/pkg/client/rest/news"

func (c *Client) News() *news.Request {
return news.NewRequest(c.c)
}
19 changes: 19 additions & 0 deletions benzinga/news_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package benzinga

import (
"context"
"testing"

"github.com/stretchr/testify/require"
)

func TestNews(t *testing.T) {
client := NewClient(nil).News()
client.SetAPIToken("68f891dba6ba4c9bae19f4c78c4d64d1")

ctx := context.Background()

resp, err := client.Exec(ctx)
require.NoError(t, err)
require.Empty(t, resp)
}
47 changes: 47 additions & 0 deletions cmd/benzinga/benzinga.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package benzinga

import (
"fmt"
"log"
"runtime/debug"

"github.com/Benzinga/sdk-go/internal/cli"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

var config cli.Config

func Run(version string) {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
fmt.Println(info)
}

logger, err := zap.NewDevelopment()
if err != nil {
log.Fatalln("logger setup failed: ", err)
}

zap.ReplaceGlobals(logger)

defer logger.Sync()

rootCmd := &cobra.Command{
Use: "benzinga",
Short: "a cli for Benzinga services",
Long: `benzinga is a CLI to interact with Benzinga services.`,
Version: version,
}

rootCmd.PersistentFlags().BoolVar(&config.Interactive, "no-interactive", false, "disable interactive prompts")
rootCmd.PersistentFlags().BoolVar(&config.Debug, "debug", false, "enable debug logging")

newsCommands := loadNewsCommands()
infoCommands := loadInfoCommands()

rootCmd.AddCommand(newsCommands, infoCommands)

if err := rootCmd.Execute(); err != nil {
zap.L().Error("execution error", zap.Error(err))
}
}
25 changes: 25 additions & 0 deletions cmd/benzinga/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package benzinga

import (
"fmt"

"github.com/spf13/cobra"
)

const infoText = "For Support Content licensing@benzinga.com or see https://github.com/Benzinga/sdk-go"

func loadInfoCommands() *cobra.Command {
command := &cobra.Command{
Use: "info",
Short: "prints into about the benzinga cli",
Run: func(cmd *cobra.Command, args []string) {
printInfo()
},
}

return command
}

func printInfo() {
fmt.Println(infoText)
}
30 changes: 30 additions & 0 deletions cmd/benzinga/news.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package benzinga

import (
"github.com/Benzinga/sdk-go/internal/news/rest/export"
"github.com/spf13/cobra"
)

func loadNewsCommands() *cobra.Command {
command := &cobra.Command{
Use: "news",
}

// Subcommands

exportConfig := export.NewConfig(&config)

exp := &cobra.Command{
Use: "export",
Short: "start export from News API",
Run: func(cmd *cobra.Command, args []string) {
export.Start(exportConfig)
},
}

exp.LocalNonPersistentFlags().StringVarP(&exportConfig.OutputDirectory, "dir", "d", "", "writeable directory to place export files")

command.AddCommand(exp)

return command
}
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/Benzinga/sdk-go

go 1.16

require (
github.com/go-playground/validator/v10 v10.9.0
github.com/manifoldco/promptui v0.8.0
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.0
go.etcd.io/bbolt v1.3.6
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.0
nhooyr.io/websocket v1.8.7
)
Loading