Skip to content

Commit

Permalink
Merge 7ec606b into e0958a0
Browse files Browse the repository at this point in the history
  • Loading branch information
shavit committed Nov 19, 2018
2 parents e0958a0 + 7ec606b commit dd2bf6c
Show file tree
Hide file tree
Showing 32 changed files with 110 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: elixir

elixir:
- 1.3.0
- 1.5.2

otp_release:
- 18.3
- 19.0

env:
- MIX_ENV=test
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ config :streamex, region: "api_region",
secret: "api_secret"
```

By default it will use these environment variables:

* `STREAMIO_REGION`
* `STREAMIO_KEY`
* `STREAMIO_SECRET`


## Usage

Refer to [Streamex documentation](https://sixfingers.github.io/streamex).
Expand Down
29 changes: 4 additions & 25 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,8 @@
# 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
# 3rd-party users, it should be done in your "mix.exs" file.
config :logger, level: :debug

# You can configure for your application as:
#
# config :streamex, key: :value
#
# And access this configuration in your application as:
#
# Application.get_env(:streamex, :key)
#
# Or configure a 3rd-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"
config :streamex, region: System.get_env("STREAMIO_REGION"),
key: System.get_env("STREAMIO_KEY") || "8andj8c67ycp",
secret: System.get_env("STREAMIO_SECRET") || "6anbcfx3a5awa62ehtmjfnzdn74shg9tcbbwrpfrdmeaf2t5f3pddfsj9ewpjnv7"
34 changes: 0 additions & 34 deletions config/test.exs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/d2d6fc2c-5e5a-11e6-8080-80017383369d/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/d2d6fc2c-5e5a-11e6-8080-80017383369d/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"32ms\", \"removed\": \"d2d6fc2c-5e5a-11e6-8080-80017383369d\"}",
Expand All @@ -32,4 +32,4 @@
"type": "ok"
}
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/tony:elixir/?api_key=8andj8c67ycp&foreign_id=1"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/tony:elixir/?api_key=8andj8c67ycp&foreign_id=1"
},
"response": {
"body": "{\"duration\": \"10ms\", \"removed\": \"tony:elixir\"}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/activities_get_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/?limit=25&offset=0&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/?limit=25&offset=0&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"15ms\", \"next\": \"\", \"results\": [{\"actor\": \"Tony\", \"foreign_id\": \"tony:elixir\", \"id\": \"cee9cdac-5e68-11e6-8080-80017383369d\", \"object\": \"Elixir\", \"origin\": null, \"target\": null, \"time\": \"2016-08-09T19:38:12.241758\", \"to\": [], \"verb\": \"like\"}, {\"actor\": \"Tony\", \"custom_field\": \"custom_value\", \"foreign_id\": \"tony:elixir\", \"id\": \"ce825654-5e68-11e6-8080-80017383369d\", \"object\": \"Elixir\", \"origin\": null, \"target\": null, \"time\": \"2016-08-09T19:38:11.563682\", \"to\": [], \"verb\": \"like\"}]}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user:/jessica/?limit=25&offset=0&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user:/jessica/?limit=25&offset=0&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"exception\": \"GetStreamAPI404\", \"detail\": \"sorry you've hit a 404\"}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/activities_post_activities.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"activities\": [{\"actor\": \"Tony\", \"foreign_id\": null, \"id\": \"cfaae60e-5e68-11e6-8080-800043f34a24\", \"object\": \"Ruby\", \"origin\": null, \"target\": null, \"time\": \"2016-08-09T19:38:13.507227\", \"to\": [], \"verb\": \"like\"}, {\"actor\": \"Tony\", \"foreign_id\": null, \"id\": \"cfabe3a6-5e68-11e6-8080-80003cc41130\", \"object\": \"PHP\", \"origin\": null, \"target\": null, \"time\": \"2016-08-09T19:38:13.513719\", \"to\": [], \"verb\": \"dislike\"}], \"duration\": \"38ms\"}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/activities_post_activity.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"activities\": [{\"actor\": \"Tony\", \"foreign_id\": \"tony:elixir\", \"id\": \"cee9cdac-5e68-11e6-8080-80017383369d\", \"object\": \"Elixir\", \"origin\": null, \"target\": null, \"time\": \"2016-08-09T19:38:12.241758\", \"to\": [], \"verb\": \"like\"}], \"duration\": \"26ms\"}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user:/jessica/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user:/jessica/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"exception\": \"GetStreamAPI404\", \"detail\": \"sorry you've hit a 404\"}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"activities\": [{\"actor\": \"Tony\", \"custom_field\": \"custom_value\", \"foreign_id\": \"tony:elixir\", \"id\": \"ce825654-5e68-11e6-8080-80017383369d\", \"object\": \"Elixir\", \"origin\": null, \"target\": null, \"time\": \"2016-08-09T19:38:11.563682\", \"to\": [], \"verb\": \"like\"}], \"duration\": \"26ms\"}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/add_to_many/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/add_to_many/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"25ms\"}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/add_to_many/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/add_to_many/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"code\": 4, \"detail\": \"Errors for fields 'feeds'\", \"duration\": \"7ms\", \"exception\": \"InputException\", \"exception_fields\": {\"feeds\": [{\"0\": [\"Invalid value.\"]}]}, \"status_code\": 400}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/activities/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/activities/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"code\": 4, \"detail\": \"Errors for fields '{'time': [u'This field is required.']}'\", \"duration\": \"11ms\", \"exception\": \"InputException\", \"exception_fields\": [{\"time\": [\"This field is required.\"]}], \"status_code\": 400}",
Expand All @@ -32,4 +32,4 @@
"type": "ok"
}
}
]
]
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_delete_follow.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/following/user:jessica/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/following/user:jessica/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"19ms\"}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_delete_follow_invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/following/user::jessica/?api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/following/user::jessica/?api_key=8andj8c67ycp"
},
"response": {
"body": "{\"code\": 4, \"detail\": \"Broken feed specification, please specify as flat:42\", \"duration\": \"7ms\", \"exception\": \"InputException\", \"status_code\": 400}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_get_followers.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/jessica/followers/?limit=25&offset=0&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/jessica/followers/?limit=25&offset=0&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"12ms\", \"results\": [{\"created_at\": \"2016-08-09T19:40:55.087Z\", \"feed_id\": \"user:eric\", \"target_id\": \"user:jessica\", \"updated_at\": \"2016-08-09T19:40:55.087Z\"}]}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_get_following.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/following/?limit=25&offset=0&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/following/?limit=25&offset=0&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"14ms\", \"results\": [{\"created_at\": \"2016-08-09T19:38:14.672Z\", \"feed_id\": \"user:eric\", \"target_id\": \"user:deborah\", \"updated_at\": \"2016-08-09T19:38:14.672Z\"}]}",
Expand Down
4 changes: 2 additions & 2 deletions fixture/vcr_cassettes/feed_post_batch_follow.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/follow_many/?activity_copy_limit=300&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/follow_many/?activity_copy_limit=300&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"15ms\"}",
Expand All @@ -33,4 +33,4 @@
"type": "ok"
}
}
]
]
4 changes: 2 additions & 2 deletions fixture/vcr_cassettes/feed_post_batch_follow_invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/follow_many/?activity_copy_limit=300&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/follow_many/?activity_copy_limit=300&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"code\": 4, \"detail\": \"Errors for fields '{'target': [u'Invalid value.']}'\", \"duration\": \"7ms\", \"exception\": \"InputException\", \"exception_fields\": [{\"target\": [\"Invalid value.\"]}], \"status_code\": 400}",
Expand All @@ -33,4 +33,4 @@
"type": "ok"
}
}
]
]
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_post_follow.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user/eric/following/?activity_copy_limit=300&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user/eric/following/?activity_copy_limit=300&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"duration\": \"11ms\"}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_post_follow_inexistent.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/alien/eric/following/?activity_copy_limit=300&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/alien/eric/following/?activity_copy_limit=300&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"code\": 6, \"detail\": \"The following feeds are not configured: 'alien'\", \"duration\": \"8ms\", \"exception\": \"FeedConfigException\", \"status_code\": 400}",
Expand Down
2 changes: 1 addition & 1 deletion fixture/vcr_cassettes/feed_post_follow_invalid.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"connect_timeout": 3000
},
"request_body": "",
"url": "https://api.getstream.io/api/feed/user:/mark/following/?activity_copy_limit=300&api_key=8andj8c67ycp"
"url": "https://api.stream-io-api.com/api/v1.0/feed/user:/mark/following/?activity_copy_limit=300&api_key=8andj8c67ycp"
},
"response": {
"body": "{\"exception\": \"GetStreamAPI404\", \"detail\": \"sorry you've hit a 404\"}",
Expand Down
4 changes: 2 additions & 2 deletions lib/streamex/activities.ex
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ defmodule Streamex.Activities do
{:ok, nil}
"""
def update(feed, %{} = activity) do
def update(feed, activity) when is_map(activity) do
update(feed, [activity])
end
def update(feed, [%{} | _] = activities) do
def update(feed, activities) when is_list(activities) do
Request.new
|> with_method(:post)
|> with_path(endpoint_update())
Expand Down
5 changes: 2 additions & 3 deletions lib/streamex/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ defmodule Streamex.Client do

import HTTPoison, only: [request: 5]
alias Streamex.{Request, Config, Token}
alias Timex.DateTime

@doc """
Prepares a `Streamex.Request` for execution.
Basically finalizes a request url.
Returns a `Streamex.Request`.
"""
def prepare_request(%Request{} = req) do
uri = URI.merge(Config.base_url, req.path)
uri = URI.merge(req.host, req.path)
query = Map.merge(req.params, %{"api_key" => Config.key}) |> URI.encode_query
uri = %{uri | query: query}
%{req | url: to_string(uri)}
Expand Down Expand Up @@ -58,7 +57,7 @@ defmodule Streamex.Client do

defp sign_request_with_key_secret(%Request{} = req, key, secret) do
algoritm = "hmac-sha256"
{_, now} = DateTime.local() |> Timex.format("{RFC822}")
{:ok, now} = Timex.now |> Timex.format("{RFC822}")

api_key_header = {"X-Api-Key", key}
date_header = {"Date", now}
Expand Down
9 changes: 5 additions & 4 deletions lib/streamex/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ defmodule Streamex.Config do
for configuring the connection client.
"""

@api_url "api.getstream.io/api"
@default_timeout 3000
@default_version 1.0
@default_version "v1.0"
@default_region ""

@doc """
Returns the current client's base api url.
# TODO: Remove this function
"""
def base_url do
case region do
"" -> "https://#{@api_url}/#{version}"
_ -> "https://#{region}-#{@api_url}/#{version}"
"" -> "https://api.stream-io-api.com/api/#{version}"
_ -> "https://#{region}-api.stream-io-api.com/api/#{version}"
end
end

Expand Down

0 comments on commit dd2bf6c

Please sign in to comment.