summary refs log tree commit diff stats
path: root/svc/post_test.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-07-11 00:57:06 -0400
committerBen Morrison <ben@gbmor.dev>2019-07-11 00:57:06 -0400
commitf13255f2e6b248902192a8a124ebc8c2c9291627 (patch)
tree9196f30ab805d79e93c1d1292f0e4a0a31ac33e0 /svc/post_test.go
parent9d9a2e5a7131424e1c63c056d4599bbb550cc98a (diff)
downloadgetwtxt-f13255f2e6b248902192a8a124ebc8c2c9291627.tar.gz
license notice at top of each file
Diffstat (limited to 'svc/post_test.go')
-rw-r--r--svc/post_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/svc/post_test.go b/svc/post_test.go
index 87db88d..f799a08 100644
--- a/svc/post_test.go
+++ b/svc/post_test.go
@@ -1,3 +1,22 @@
+/*
+Copyright (c) 2019 Ben Morrison (gbmor)
+
+This file is part of Getwtxt.
+
+Getwtxt is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Getwtxt is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Getwtxt.  If not, see <https://www.gnu.org/licenses/>.
+*/
+
 package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
*/ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package bpod

import (
	"encoding/json"
	"fmt"
	"math/rand"

	"framagit.org/andinus/cetus/pkg/request"
)

type Res struct {
	StartDate     string `json:"startdate"`
	FullStartDate string `json:"fullstartdate"`
	EndDate       string `json:"enddate"`
	Url           string `json:"url"`
	UrlBase       string `json:"urlbase"`
	Copyright     string `json:"copyright"`
	CopyrightLink string `json:"copyrightlink"`
	Title         string `json:"title"`
	Hsh           string `json:"hsh"`
}

type List struct {
	Photos []Res `json:"images"`
}

// UnmarshalJson will take body as input & unmarshal it to res
func UnmarshalJson(body string) (Res, error) {
	list := List{}
	res := Res{}

	err := json.Unmarshal([]byte(body), &list)
	if err != nil {
		return res, fmt.Errorf("UnmarshalJson failed\n%s", err.Error())
	}

	res = list.Photos[rand.Intn(len(list.Photos))]
	return res, nil
}

// GetJson returns json response received from the api
func GetJson(reqInfo map[string]string) (string, error) {
	params := make(map[string]string)
	params["format"] = "js"
	params["n"] = "1"

	// if random is true then fetch 7 photos
	if reqInfo["random"] == "true" {
		params["n"] = "7"

	}

	body, err := request.GetRes(reqInfo["api"], params)
	return string(body), err
}