From cc6711285210c1f86bd1bb62f8e086b12e3cec01 Mon Sep 17 00:00:00 2001 From: George Karagoulis Date: Sun, 12 Dec 2021 12:04:35 -0800 Subject: [PATCH 1/3] Ran go mod tidy to get build working --- go.sum | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/go.sum b/go.sum index 5fd4ec3..679d4b2 100644 --- a/go.sum +++ b/go.sum @@ -1,9 +1,15 @@ github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw= github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= +github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= +github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= +github.com/karagog/testutil-go v0.0.0-20211208183738-8c37cec26dcb h1:rhZdM6f/j2K7LMz876Tv/4o/pNVL+EB3CzTbtr6r/Lo= +github.com/karagog/testutil-go v0.0.0-20211208183738-8c37cec26dcb/go.mod h1:0ssa4Oum+vNHm7sMVKEU1zGE26K+47lvoZBeY8DJ2rY= github.com/spf13/cobra v0.0.3 h1:ZlrZ4XsMRm04Fr5pSFxBgfND2EBVa1nLpiy1stUsX/8= github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= From ee2f0115552c3c51619538856f6be9cae0a1dcba Mon Sep 17 00:00:00 2001 From: George Karagoulis Date: Sun, 12 Dec 2021 12:04:49 -0800 Subject: [PATCH 2/3] Add news command. --- cmd/news.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 cmd/news.go diff --git a/cmd/news.go b/cmd/news.go new file mode 100644 index 0000000..73fcf90 --- /dev/null +++ b/cmd/news.go @@ -0,0 +1,49 @@ +// Copyright (c) 2019-2020 The iexcloud developers. All rights reserved. +// Project site: https://github.com/goinvest/iexcloud +// Use of this source code is governed by a MIT-style license that +// can be found in the LICENSE file for the project. + +package cmd + +import ( + "context" + "encoding/json" + "fmt" + "log" + "strconv" + + "github.com/goinvest/iexcloud-examples/domain" + iex "github.com/goinvest/iexcloud/v2" + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(newsCmd) +} + +var newsCmd = &cobra.Command{ + Use: "news [symbol] [limit]", + Short: "Retrieve news articles about the given symbol. Pass the special symbol 'market' to get market news about a variety of stocks.", + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + cfg, err := domain.ReadConfig(configFileFlag) + if err != nil { + log.Fatalf("Error reading config file: %s", err) + } + num, err := strconv.Atoi(args[1]) + if err != nil { + log.Fatalf("Invalid limit: %s", err) + } + client := iex.NewClient(cfg.Token, iex.WithBaseURL(cfg.BaseURL)) + bs, err := client.News(context.Background(), args[0], num) + if err != nil { + log.Fatalf("Error getting news: %s", err) + } + b, err := json.MarshalIndent(bs, "", " ") + if err != nil { + log.Fatalf("Error marshaling into JSON: %s", err) + } + fmt.Println("## News ##") + fmt.Println(string(b)) + }, +} From dc89b52b0ff6eeb89de9cc24060d6c6c63d827b2 Mon Sep 17 00:00:00 2001 From: George Karagoulis Date: Sun, 12 Dec 2021 12:08:07 -0800 Subject: [PATCH 3/3] Remove glog dep until it's merged into iexcloud repo. --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 679d4b2..5866aaa 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,6 @@ github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= -github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ= -github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4= github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=