func main() {
	m := medium.NewClientWithAccessToken("MEDIUM_SELF_ISSUED_ACCESS_TOKEN")

	// Get profile details of the user identified by the access token.
	u, err := m.GetUser()
	if err != nil {
		log.Fatal(err)
	}
	content := ''
	title := ''
	// Create a draft post.
	p, err := m.CreatePost(medium.CreatePostOptions{
		UserID:        u.ID,
		Title:         title,
		Content:       content,
		ContentFormat: medium.ContentFormatMarkdown,
		PublishStatus: medium.PublishStatusPublic,
	})

	if err != nil {
		log.Fatal(err)
	}

	log.Println(u, p)
}
Esempio n. 2
0
func main() {
	var config Configuration

	app := cli.NewApp()
	app.Name = "Medium Cli"
	app.Version = "0.0.1"
	app.Usage = "Publish to Medium.com using the command line"

	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:  "status, s",
			Value: "publish",
			Usage: "Status of the post",
		},
		cli.StringFlag{
			Name:  "title, t",
			Usage: "Post tile",
		},
		cli.StringFlag{
			Name:  "markdown, m",
			Usage: "Markdown file to post to Medium",
		},
	}

	app.Action = func(c *cli.Context) {
		status := c.String("status")
		title := c.String("title")
		markdownFile := c.String("markdown")

		// check post status
		if status != "publish" {
			println(status + " is not a supported status")
			return
		}

		if markdownFile == "" {
			println("Please specify a markdown file")
			return
		}

		if title == "" {
			println("Please specify a title")
			return
		}

		// get post as markdown file
		data, err := ioutil.ReadFile(markdownFile)
		check(err)

		markdown := string(blackfriday.MarkdownCommon([]byte(data)))

		fmt.Println("Markdown: " + markdown)

		dir, err := homedir.Dir()
		check(err)

		println("Get config file from " + dir)

		if _, err := toml.DecodeFile(dir+"/medium-cli-conf.toml", &config); err != nil {
			fmt.Println(err)
			return
		}

		println(status + " something")
		fmt.Println("Found token: " + config.Token)

		mediumClient := medium.NewClientWithAccessToken(config.Token)

		mediumUser, err := mediumClient.GetUser()
		check(err)

		post, err := mediumClient.CreatePost(medium.CreatePostOptions{
			UserID:        mediumUser.ID,
			Title:         title,
			Content:       markdown,
			ContentFormat: medium.ContentFormatHTML,
			PublishStatus: medium.PublishStatusDraft,
		})

		check(err)

		log.Println(mediumUser, post)
	}

	app.Run(os.Args)
}
Esempio n. 3
0
File: medium.go Progetto: bcho/read
func NewMediumPublisher(token string) *mediumPublisher {
	return &mediumPublisher{client: medium.NewClientWithAccessToken(token)}
}