vista_client v0.1.3 VistaClient
Documentation for VistaClient.
Examples
iex> {:ok, cinemas} = VistaClient.get_cinemas()
iex> cinemas |> Enum.find(fn cinema -> cinema.id == 1001 end)
%VistaClient.Cinema{id: 1001, name: "Delphi Lux"}
Link to this section Summary
Functions
Extracts and validates parameters from opts list for use with make_payload
Performs a HTTP-GET request and decodes the JSON response into a struct.
Returns {:ok,
Callback implementation for VistaClient.Behaviour.get_cinemas/0
.
Callback implementation for VistaClient.Behaviour.get_scheduled_films/0
.
Callback implementation for VistaClient.Behaviour.get_session_availabilty/1
.
Callback implementation for VistaClient.Behaviour.get_sessions/0
.
creates auth and content-type and accept headers
Builds a JSON map formatted to receive membership details. If no user_session_id is specified, a temporaray random one will be generated.
Returns
Creates JSON post body (a string) to select API endpoints
Roughly checks if the given binary has the form of a valid e-mail address using a not fully RFC-compliant regular expression taken from https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)
Link to this section Types
command()
command() :: :validate_member | :add_concessions | :start_external_payment | :complete_order
retrieved_entity()
retrieved_entity() :: :cinemas | :scheduled_films | :sessions | command()
Link to this section Functions
add_concession(head_office_item_code, cinema_id, user_session_id \\ nil)
add_variable_price_concession(head_office_item_code, price_in_cents, cinema_id, user_session_id \\ nil)
complete_order(user_session_id, customer_email, payment_value, payment_reference)
extract_payload_parameters(atom, opts)
Extracts and validates parameters from opts list for use with make_payload
Examples
iex> VistaClient.extract_payload_parameters(:validate_member, user_session_id: :atom, member_card_number: 23)
{:error, {:invalid, [user_session_id: :atom]}}
iex> VistaClient.extract_payload_parameters(:validate_member, user_session_id: "123", member_card_number: "555123456")
{:ok, [member_card_number: "555123456", user_session_id: "123"]}
iex> VistaClient.extract_payload_parameters(:add_concessions, user_session_id: "test", cinema_id: "007", head_office_item_code: "666")
{:ok, [user_session_id: "test", cinema_id: "007", head_office_item_code: "666", variable_price: nil]}
iex> VistaClient.extract_payload_parameters(:add_concessions, user_session_id: "000", head_office_item_code: "aaa", cinema_id: "123", variable_price: 500)
{:ok, [user_session_id: "000", cinema_id: "123", head_office_item_code: "aaa", variable_price: 500]}
iex> VistaClient.extract_payload_parameters(:start_external_payment, user_session_id: "777")
{:ok, [user_session_id: "777"]}
iex> VistaClient.extract_payload_parameters(:complete_order, user_session_id: "1", customer_email: "foo@bar.baz", payment_value: 2500, pament_reference: "1nc19-832-a83uhd")
{:error, {:invalid, [payment_reference: nil]}}
iex> VistaClient.extract_payload_parameters(:complete_order, user_session_id: "1", customer_email: "foo@bar.baz", payment_value: 2500, payment_reference: "1nc19-832-a83uhd")
{:ok,[user_session_id: "1", customer_email: "foo@bar.baz", payment_value: 2500, payment_reference: "1nc19-832-a83uhd"]}
get(what, opts \\ [])
Performs a HTTP-GET request and decodes the JSON response into a struct.
Returns {:ok,
Options:
- :output_raw_maps => set to true to get plain decoded JSON map
get_cinemas()
Callback implementation for VistaClient.Behaviour.get_cinemas/0
.
get_endpoints()
get_scheduled_films()
Callback implementation for VistaClient.Behaviour.get_scheduled_films/0
.
get_session_availabilty(session_id)
Callback implementation for VistaClient.Behaviour.get_session_availabilty/1
.
get_sessions()
Callback implementation for VistaClient.Behaviour.get_sessions/0
.
make_basic_headers()
creates auth and content-type and accept headers
make_payload(atom, list)
Builds a JSON map formatted to receive membership details. If no user_session_id is specified, a temporaray random one will be generated.
Examples
iex> VistaClient.make_payload(:validate_member, member_card_number: "1234", user_session_id: "temp_foo")
%{"UserSessionId" => "temp_foo", "MemberCardNumber" => "1234", "ReturnMember" => true}
iex> VistaClient.make_payload(:start_external_payment, user_session_id: "idontwannapay")
%{"AutoCompleteOrder" => false, "UserSessionId" => "idontwannapay"}
iex> VistaClient.make_payload(:complete_order, user_session_id: "idontwannapay", customer_email: "idont@wanna.pay", payment_value: 1234, payment_reference: "buttheypaidanyway")
%{"BookingType" => 0, "CustomerEmail" => "idont@wanna.pay", "CustomerName" => "WEBSHOP", "CustomerPhone" => "WEBSHOP", "GenerateConcessionVoucherPrintStream" => true, "GeneratePrintStream" => true, "PaymentInfo" => %{"BankReference" => "buttheypaidanyway", "BillFullOutstandingAmount" => true, "BillingValueCents" => 1234, "CardType" => "PAYPAL", "PaymentValueCents" => 1234}, "PerformPayment" => false, "PrintStreamType" => 1, "PrintTemplateName" => "www_P@H", "ReturnPrintStream" => true, "UserSessionId" => "idontwannapay"}
make_request(url)
make_structs(endpoints, atom)
make_url_for(action, api_url)
make_url_for(atom, api_url, arg3)
Returns
- {:ok, true} if VISTA server seems up
- {:ok, false} if not
- {:error, reason} on config error
EXAMPLES
iex> VistaClient.online?()
{:ok, true}
payload_for(command, opts \\ [])
Creates JSON post body (a string) to select API endpoints
Examples
iex> VistaClient.payload_for(:validate_member, member_card_number: 1234, user_session_id: 666)
{:ok, "{\"MemberCardNumber\":\"1234\",\"ReturnMember\":true,\"UserSessionId\":\"666\"}"}
iex> VistaClient.payload_for(:add_concessions, user_session_id: "me", head_office_item_code: "2019")
{:error, {:missing, :cinema_id}}
iex> VistaClient.payload_for :add_concessions, user_session_id: "abc", cinema_id: "123", head_office_item_code: "XYZ"
{:ok, "{\"CinemaId\":\"123\",\"Concessions\":[{\"GetBarcodeFromVGC\":true,\"HeadOfficeItemCode\":\"XYZ\",\"Quantity\":1}],\"UserSessionId\":\"abc\"}"}
iex> VistaClient.payload_for :start_external_payment
{:error, {:missing, :user_session_id}}
iex> VistaClient.payload_for(:start_external_payment, user_session_id: "7357")
{:ok, "{\"AutoCompleteOrder\":false,\"UserSessionId\":\"7357\"}"}
iex(23)> VistaClient.payload_for(:complete_order, user_session_id: "f00", customer_email: "customer@e.mail", payment_value: 1000, payment_reference: "1337")
{:ok, "{\"BookingType\":0,\"CustomerEmail\":\"customer@e.mail\",\"CustomerName\":\"WEBSHOP\",\"CustomerPhone\":\"WEBSHOP\",\"GenerateConcessionVoucherPrintStream\":true,\"GeneratePrintStream\":true,\"PaymentInfo\":{\"BankReference\":\"1337\",\"BillFullOutstandingAmount\":true,\"BillingValueCents\":1000,\"CardType\":\"PAYPAL\",\"PaymentValueCents\":1000},\"PerformPayment\":false,\"PrintStreamType\":1,\"PrintTemplateName\":\"www_P@H\",\"ReturnPrintStream\":true,\"UserSessionId\":\"f00\"}"}
post(where, param_list, opts \\ [])
post_request(url, payload)
quickcheck_email_address(address)
Roughly checks if the given binary has the form of a valid e-mail address using a not fully RFC-compliant regular expression taken from https://html.spec.whatwg.org/multipage/input.html#e-mail-state-(type=email)
Examples
iex> VistaClient.quickcheck_email_address(123)
{:error, {:invalid, [email: 123]}}
iex> VistaClient.quickcheck_email_address("foo@bar.baz")
{:ok, "foo@bar.baz"}
iex> VistaClient.quickcheck_email_address("dash.is.not@-allowed.everywhere")
{:error, {:invalid, [email: "dash.is.not@-allowed.everywhere"]}}
start_external_payment(user_session_id)
url_for(what, opts \\ [])
url_for(retrieved_entity(), keyword()) :: {:ok, url()} | {:error, reason()}