{"id":20041242,"url":"https://github.com/gernest/adapi","last_synced_at":"2025-07-11T23:37:41.035Z","repository":{"id":33533688,"uuid":"37179792","full_name":"gernest/adapi","owner":"gernest","description":"Personal advertisment management API service","archived":false,"fork":false,"pushed_at":"2015-08-12T12:48:14.000Z","size":160,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-12T19:25:00.545Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gernest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-10T06:33:23.000Z","updated_at":"2015-12-05T09:14:09.000Z","dependencies_parsed_at":"2022-09-03T04:31:31.430Z","dependency_job_id":null,"html_url":"https://github.com/gernest/adapi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Fadapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Fadapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Fadapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gernest%2Fadapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gernest","download_url":"https://codeload.github.com/gernest/adapi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241470366,"owners_count":19968041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T10:45:57.056Z","updated_at":"2025-03-02T06:48:41.621Z","avatar_url":"https://github.com/gernest.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# adapi [![Build Status](https://drone.io/github.com/gernest/adapi/status.png)](https://drone.io/github.com/gernest/adapi/latest)[![GoDoc](https://godoc.org/github.com/gernest/adapi?status.svg)](https://godoc.org/github.com/gernest/adapi)[![Coverage Status](https://coveralls.io/repos/gernest/adapi/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/gernest/adapi?branch=master)\nPersonal advertisment management API service.\n\n## Warning\nThis is experimental, for educational only. The problem at hand is more complex. But if you know what you are doing, its okay and you can help make this project better.\n\n## Overview\nAdapi is a library, providing handlers to construct a personalised advertisment service. It uses JSON as the main data exchange format.\n\nAn ad is persceived to be an `interface{}` that is inside a air time. Air time is a period in which the given ad should be broadcasted.\n\nA channel is an object, which has a schedule(or a slice of showtimes). Each showtime is limited to a given period. showtimes contains the air times( which have ads). Now you can dig the source to see the definitions of these types, they are straight.\n\n## Storage\nAdapi can be used with whatever storage you prefer, it should only satisfy the following interface\n\n```go\ntype Store interface {\n\tSet(key interface{}, value interface{}) error\n\tGet(key interface{}) (interface{}, error)\n}\n```\n\nI have implemented a simple store `MemoryStore` which uses a map for key, value lookup. Read [here](store.go) to see how to implement a store backend.\n\n## Confussion about Channels\nI haven't yet found a good name to describe better  a sort of broadcasting entity, with a schedule and pumps different data depending on what time of the day other than a channel.\n\nSo, it might be confusing using this word channel, which might also be refering to golang channels. To make stuffs clear. The term \"golang channel\" will be used to refer to Go programming languaguage channels and \"channel\" or \"AdAPI channel\" will be used to refer to objects of type `Channel` throughout the project\n\n## Does this use golang channels?\nNope, havent' found the need for them yet. But if you think they can be useful here, feel free to vent about it.'\n\n## Usage\nInitializing the handlers requires an `AdAPI` instance, which is created by the following method.\n\n```go\nfunc NewAdAPI(s Store) *AdAPI {\n\treturn \u0026AdAPI{s}\n}\n```\n\nSo, you only need to implement the `Store` interface to initialize the handler.\n\n\nThe following are examples of how the handlers can be used.\n\n### Post\n```go\nfunc ExampleAdAPI_Post() {\n\tvar (\n\t\tpostPath    = \"/adapi/post\"\n\t\tchannelName = \"adapi\"\n\t\tstart       = time.Now()\n\t\tduration    = time.Hour\n\t\tdata        = \"hello world\"\n\t)\n\n\tstore := NewMemStore()\n\tapi := NewAdAPI(store)\n\n\t// create a handle\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(postPath, api.Post)\n\n\t// we are using a test server for this example\n\tserver := httptest.NewServer(mux)\n\tdefer server.Close()\n\n\t// The test server runs on random port, the only way to hit the correct socket is by\n\t// reconstructing the url\n\tcurrentPostPath := fmt.Sprintf(\"%s%s\", server.URL, postPath)\n\n\t// create  data to be sent with the request\n\treq := \u0026Request{\n\t\tChannelName: channelName,\n\t\tAir:         NewAir(start, duration, data),\n\t}\n\treqData, err := json.Marshal(req)\n\tif err != nil {\n\t\t// do something\n\t}\n\n\t// create a client.\n\tclient := \u0026http.Client{}\n\tresponse, err := client.Post(currentPostPath, \"application/json\", strings.NewReader(string(reqData)))\n\tif err != nil {\n\t\t// do something\n\t}\n\tbuf := \u0026bytes.Buffer{}\n\tio.Copy(buf, response.Body)\n\tdefer response.Body.Close()\n\n\t// The response should be a Channel, this Channel will contain the airtime we have posted\n\tch := \u0026Channel{}\n\terr = json.Unmarshal(buf.Bytes(), ch)\n\tif err != nil {\n\t\t// do something\n\t}\n\tcurrentShowTime := ch.Show()\n\tcurrentAiring := currentShowTime.Show()\n\n\t// Within an hour range, we will should get the same air data.\n\tfmt.Println(currentAiring.Data)\n\n\t//Output:\n\t//hello world\n}\n```\n\n\n### Get\n`AdAPI.Get` uses url query paramenters to decide which part of the channel to render. For instance the url with  a query like this `?chn=adapi\u0026dir=air\"`, means get what is on air, for the channel with channel name of adapi.\n\nCheck this example\n```go\n\nfunc ExampleAdAPI_Get() {\n\tvar (\n\t\tgetPath     = \"/adapi/get\"\n\t\tchannelName = \"adapi\"\n\t\tdata        = \"hello world\"\n\t)\n\tstore := NewMemStore()\n\n\t// create a channel and an air time\n\tc := \u0026Channel{Name: channelName}\n\tCreateDaySchedule(c)\n\ta := NewAir(time.Now(), time.Minute, data)\n\terr := AddAirTime(c, a)\n\tif err != nil {\n\t\t// do something\n\t}\n\n\t// store the channel\n\tstore.Set(c.Name, c)\n\n\tapi := NewAdAPI(store)\n\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(getPath, api.Get)\n\n\tserver := httptest.NewServer(mux)\n\tdefer server.Close()\n\n\tclient := \u0026http.Client{}\n\tvars := url.Values{\n\t\t\"chn\": {channelName},\n\t\t\"dir\": {\"air\"},\n\t}\n\tcurrentGetPath := fmt.Sprintf(\"%s%s?%s\", server.URL, getPath, vars.Encode())\n\tresponse, err := client.Get(currentGetPath)\n\tif err != nil {\n\t\t// do something\n\t}\n\n\tbuf := \u0026bytes.Buffer{}\n\tio.Copy(buf, response.Body)\n\tdefer response.Body.Close()\n\n\tair := \u0026Air{}\n\terr = json.Unmarshal(buf.Bytes(), air)\n\tif err != nil {\n\t\t// do something\n\t}\n\tfmt.Println(air.Data)\n\n\t// Output:\n\t// hello world\n\n}\n\n```\n\nContributing\n============\n\nPlease feel free to submit issues, fork the repository and send pull requests!\n\nContributions are welcome and will be fully credited. Please see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Author\nGeofrey Ernest\n\n## License\n\nThis project is under the MIT License. See the [LICENSE](LICENCE) file for the full license text.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgernest%2Fadapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgernest%2Fadapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgernest%2Fadapi/lists"}