Skip to content

Commit

Permalink
Fix cloudex configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Feb 17, 2017
1 parent f87cc07 commit 13aa82d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 20 deletions.
6 changes: 6 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ config :code_corps,
config :segment,
write_key: System.get_env("SEGMENT_WRITE_KEY")

config :code_corps, :cloudex, Cloudex
config :cloudex,
api_key: System.get_env("CLOUDEX_API_KEY"),
secret: System.get_env("CLOUDEX_SECRET"),
cloud_name: System.get_env("CLOUDEX_CLOUD_NAME")

# Configures random icon color generator
config :code_corps, :icon_color_generator, CodeCorps.RandomIconColor.Generator

Expand Down
9 changes: 4 additions & 5 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ config :code_corps, CodeCorps.Mailer,
config :code_corps,
postmark_receipt_template: "123"

# If the dev environment has no CLOUDEX_API_KEY set, we want the app to still run,
# with cloudex in test API mode
# If the dev environment has no CLOUDEX_API_KEY set, we want the app
# to still run, with cloudex in test API mode
if System.get_env("CLOUDEX_API_KEY") == nil do
config :cloudex, :cloudinary_api, Cloudex.CloudinaryApi.Test
config :cloudex, api_key: "test_key", secret: "test_secret", cloud_name: "test_cloud_name"

IO.puts("NOTE: No Cloudex configuration found. Cloudex is runnning in test mode.")
config :code_corps, :cloudex, CloudexTest
config :cloudex, api_key: "test_key", secret: "test_secret", cloud_name: "test_cloud_name"
end
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@ config :code_corps, CodeCorps.Mailer,
config :code_corps,
postmark_receipt_template: "123"

config :cloudex, :cloudinary_api, Cloudex.CloudinaryApi.Test
config :code_corps, :cloudex, CloudexTest
config :cloudex, api_key: "test_key", secret: "test_secret", cloud_name: "test_cloud_name"
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Cloudex.CloudinaryApi.Test do
defmodule CloudexTest do
@moduledoc """
Testing stub for `Cloudex`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule CodeCorps.Helpers.CloudinaryUrl do
defmodule CodeCorps.Cloudex.CloudinaryUrl do

@cloudex Application.get_env(:cloudex, :cloudinary_api)
@cloudex Application.get_env(:code_corps, :cloudex)

def for(nil, _options, version, default_color, type) do
"#{Application.get_env(:code_corps, :asset_host)}/icons/#{type}_default_#{version}_#{default_color}.png"
Expand Down
4 changes: 2 additions & 2 deletions priv/repo/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
-- PostgreSQL database dump
--

-- Dumped from database version 9.5.1
-- Dumped by pg_dump version 9.5.1
-- Dumped from database version 9.5.4
-- Dumped by pg_dump version 9.5.4

SET statement_timeout = 0;
SET lock_timeout = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
defmodule CodeCorps.Helpers.CloudinaryUrlTest do
defmodule CodeCorps.Cloudex.CloudinaryUrlTest do
alias CodeCorps.Cloudex.CloudinaryUrl
use ExUnit.Case, async: true

test "calls Cloudex.Url.for with correct arguments" do
expected_args = {:test_public_id, %{test_option: nil}}
args = CodeCorps.Helpers.CloudinaryUrl.for(:test_public_id, %{test_option: nil}, nil, nil, nil)
args = CloudinaryUrl.for(:test_public_id, %{test_option: nil}, nil, nil, nil)
assert expected_args == args
end

test "returns correct url if called without public_id" do
expected_url = "#{Application.get_env(:code_corps, :asset_host)}/icons/type1_default_version1_color1.png"
url = CodeCorps.Helpers.CloudinaryUrl.for(nil, %{}, "version1", "color1", "type1")
url = CloudinaryUrl.for(nil, %{}, "version1", "color1", "type1")
assert expected_url == url
end
end
5 changes: 3 additions & 2 deletions web/views/organization_view.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule CodeCorps.OrganizationView do
alias CodeCorps.Cloudex.CloudinaryUrl
use CodeCorps.PreloadHelpers, default_preloads: [:slugged_route, :stripe_connect_account, :organization_memberships, :projects]
use CodeCorps.Web, :view
use JaSerializer.PhoenixView
Expand All @@ -15,10 +16,10 @@ defmodule CodeCorps.OrganizationView do
has_many :projects, serializer: CodeCorps.ProjectView, identifiers: :always

def icon_large_url(organization, _conn) do
CodeCorps.Helpers.CloudinaryUrl.for(organization.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", organization.default_color, "organization")
CloudinaryUrl.for(organization.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", organization.default_color, "organization")
end

def icon_thumb_url(organization, _conn) do
CodeCorps.Helpers.CloudinaryUrl.for(organization.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", organization.default_color, "organization")
CloudinaryUrl.for(organization.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", organization.default_color, "organization")
end
end
5 changes: 3 additions & 2 deletions web/views/project_view.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
defmodule CodeCorps.ProjectView do
alias CodeCorps.Cloudex.CloudinaryUrl
alias CodeCorps.StripeService.Validators.ProjectCanEnableDonations

use CodeCorps.PreloadHelpers,
Expand Down Expand Up @@ -36,10 +37,10 @@ defmodule CodeCorps.ProjectView do
end

def icon_large_url(project, _conn) do
CodeCorps.Helpers.CloudinaryUrl.for(project.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", project.default_color, "project")
CloudinaryUrl.for(project.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", project.default_color, "project")
end

def icon_thumb_url(project, _conn) do
CodeCorps.Helpers.CloudinaryUrl.for(project.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", project.default_color, "project")
CloudinaryUrl.for(project.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", project.default_color, "project")
end
end
6 changes: 4 additions & 2 deletions web/views/user_view.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
defmodule CodeCorps.UserView do
alias CodeCorps.Cloudex.CloudinaryUrl

use CodeCorps.PreloadHelpers,
default_preloads: [
:slugged_route, :stripe_connect_subscriptions, :stripe_platform_card, :stripe_platform_customer,
Expand All @@ -23,11 +25,11 @@ defmodule CodeCorps.UserView do
has_many :user_skills, serializer: CodeCorps.UserSkillView, identifiers: :always

def photo_large_url(user, _conn) do
CodeCorps.Helpers.CloudinaryUrl.for(user.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", user.default_color, "user")
CloudinaryUrl.for(user.cloudinary_public_id, %{crop: "fill", height: 500, width: 500}, "large", user.default_color, "user")
end

def photo_thumb_url(user, _conn) do
CodeCorps.Helpers.CloudinaryUrl.for(user.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", user.default_color, "user")
CloudinaryUrl.for(user.cloudinary_public_id, %{crop: "fill", height: 100, width: 100}, "thumb", user.default_color, "user")
end

@doc """
Expand Down

0 comments on commit 13aa82d

Please sign in to comment.