Initial Commit

master
Rachel Fae Fox (foxiepaws) 2020-02-17 04:30:14 -05:00
commit 76fc9f7455
14 changed files with 232 additions and 0 deletions

4
.formatter.exs Normal file
View File

@ -0,0 +1,4 @@
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

26
.gitignore vendored Normal file
View File

@ -0,0 +1,26 @@
# The directory Mix will write compiled artifacts to.
/_build/
# If you run "mix test --cover", coverage assets end up here.
/cover/
# The directory Mix downloads your dependencies sources to.
/deps/
# Where third-party dependencies like ExDoc output generated docs.
/doc/
# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch
# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
# Also ignore archive artifacts (built via "mix archive.build").
*.ez
# Ignore package tarball (built via "mix hex.build").
steamwebapi-*.tar
# ignore secrets
/config/*.secret.exs

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# Steamwebapi
**TODO: Add description**
## Installation
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `steamwebapi` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:steamwebapi, "~> 0.1.0"}
]
end
```
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at [https://hexdocs.pm/steamwebapi](https://hexdocs.pm/steamwebapi).

31
config/config.exs Normal file
View File

@ -0,0 +1,31 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
use Mix.Config
# This configuration is loaded before any dependency and is restricted
# to this project. If another project depends on this project, this
# file won't be loaded nor affect the parent project. For this reason,
# if you want to provide default values for your application for
# third-party users, it should be done in your "mix.exs" file.
# You can configure your application as:
#
# config :steamwebapi, key: :value
#
# and access this configuration in your application as:
#
# Application.get_env(:steamwebapi, :key)
#
# You can also configure a third-party app:
#
# config :logger, level: :info
#
# It is also possible to import configuration files, relative to this
# directory. For example, you can emulate configuration per environment
# by uncommenting the line below and defining dev.exs, test.exs and such.
# Configuration from the imported file will override the ones defined
# here (which is why it is important to import them last).
#
import_config "#{Mix.env()}.exs"
import_config "#{Mix.env()}.secret.exs"

2
config/dev.exs Normal file
View File

@ -0,0 +1,2 @@
use Mix.Config
config :tesla, :adapter, Tesla.Adapter.Hackney

2
config/prod.exs Normal file
View File

@ -0,0 +1,2 @@
use Mix.Config
config :tesla, :adapter, Tesla.Adapter.Hackney

2
config/test.exs Normal file
View File

@ -0,0 +1,2 @@
use Mix.Config
config :tesla, :adapter, Tesla.Adapter.Mock

38
lib/IRemoteStorage.ex Normal file
View File

@ -0,0 +1,38 @@
defmodule IRemoteStorage do
use Tesla
plug(SteamAPI, "ISteamRemoteStorage")
plug(Tesla.Middleware.FormUrlencoded)
def _helper(c, i) do
num = Enum.count(i)
m =
i
|> Enum.with_index()
|> Enum.map(fn {x, y} ->
%{"publishedfileids[#{y}]" => x}
end)
|> Enum.reduce(fn x, xs ->
Map.merge(x, xs)
end)
Map.merge(%{"#{c}count" => num}, m)
end
def collection(collections) do
vars = _helper("collection", collections)
if {:ok, response} = post("GetCollectionDetails/v1", vars) do
Jason.decode(response.body)
end
end
def item(items) do
vars = _helper("item", items)
if {:ok, response} = post("GetPublishedFileDetails/v1", vars) do
Jason.decode(response.body)
end
end
end

37
lib/SteamAPI.ex Normal file
View File

@ -0,0 +1,37 @@
defmodule SteamAPI do
@behaviour Tesla.Middleware
# steam API helper, based off baseurl and query
@impl Tesla.Middleware
def call(env, next, interface) do
env
|> apply_base(interface)
|> apply_base("https://api.steampowered.com")
|> merge(key: Application.fetch_env!(:steamwebapi, :token))
|> Tesla.run(next)
end
defp apply_base(env, base) do
if Regex.match?(~r/^https?:\/\//i, env.url) do
# skip if url is already with scheme
env
else
%{env | url: join(base, env.url)}
end
end
defp merge(env, query) do
Map.update!(env, :query, &(&1 ++ query))
end
defp join(base, url) do
case {String.last(to_string(base)), url} do
{nil, url} -> url
{"/", "/" <> rest} -> base <> rest
{"/", rest} -> base <> rest
{_, ""} -> base
{_, "/" <> rest} -> base <> "/" <> rest
{_, rest} -> base <> "/" <> rest
end
end
end

18
lib/steamwebapi.ex Normal file
View File

@ -0,0 +1,18 @@
defmodule Steamwebapi do
@moduledoc """
Documentation for Steamwebapi.
"""
@doc """
Hello world.
## Examples
iex> Steamwebapi.hello()
:world
"""
def hello do
:world
end
end

29
mix.exs Normal file
View File

@ -0,0 +1,29 @@
defmodule Steamwebapi.MixProject do
use Mix.Project
def project do
[
app: :steamwebapi,
version: "0.1.0",
elixir: "~> 1.8",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:tesla, "~> 1.3.0"},
{:hackney, "~> 1.15.2"},
{:jason, ">= 1.0.0"}
]
end
end

13
mix.lock Normal file
View File

@ -0,0 +1,13 @@
%{
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mime": {:hex, :mime, "1.3.1", "30ce04ab3175b6ad0bdce0035cba77bba68b813d523d1aac73d9781b4d193cf8", [:mix], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"},
"tesla": {:hex, :tesla, "1.3.2", "deb92c5c9ce35e747a395ba413ca78593a4f75bf0e1545630ee2e3d34264021e", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
}

View File

@ -0,0 +1,8 @@
defmodule SteamwebapiTest do
use ExUnit.Case
doctest Steamwebapi
test "greets the world" do
assert Steamwebapi.hello() == :world
end
end

1
test/test_helper.exs Normal file
View File

@ -0,0 +1 @@
ExUnit.start()