Packages

An Elixir library (driver) for clients communicating with MQTT brokers(via the MQTT 3.1.1 protocol).

Current section

7 Versions

Jump to

Compare versions

5 files changed
+53 additions
-51 deletions
  @@ -15,7 +15,7 @@ Add Hulaaki to your project dependencies in `mix.exs`
15 15
16 16 ```elixir
17 17 def deps do
18 - [{:hulaaki, "~> 0.0.1"} ]
18 + [{:hulaaki, "~> 0.0.3"} ]
19 19 end
20 20 ```
  @@ -1,15 +1,15 @@
1 1 {<<"app">>,<<"hulaaki">>}.
2 2 {<<"build_tools">>,[<<"mix">>]}.
3 - {<<"contributors">>,[<<"Suvash Thapaliya">>]}.
4 3 {<<"description">>,<<"An MQTT 3.1.1 client library written in Elixir.">>}.
5 - {<<"elixir">>,<<"~> 1.0">>}.
4 + {<<"elixir">>,<<"~> 1.2">>}.
6 5 {<<"files">>,
7 6 [<<"lib/hulaaki.ex">>,<<"lib/hulaaki/client.ex">>,
8 7 <<"lib/hulaaki/connection.ex">>,<<"lib/hulaaki/decoder.ex">>,
9 8 <<"lib/hulaaki/encoder.ex">>,<<"lib/hulaaki/message.ex">>,<<"mix.exs">>,
10 9 <<"README.md">>,<<"LICENSE.txt">>]}.
11 10 {<<"licenses">>,[<<"MIT">>]}.
12 - {<<"links">>,[{<<"github">>,<<"https://github.com/suvash/hulaaki">>}]}.
11 + {<<"links">>,[{<<"Github">>,<<"https://github.com/suvash/hulaaki">>}]}.
12 + {<<"maintainers">>,[<<"Suvash Thapaliya">>]}.
13 13 {<<"name">>,<<"hulaaki">>}.
14 14 {<<"requirements">>,[]}.
15 - {<<"version">>,<<"0.0.2">>}.
15 + {<<"version">>,<<"0.0.3">>}.
  @@ -55,18 +55,18 @@ defmodule Hulaaki.Client do
55 55 # collection options for host port ?
56 56
57 57 def handle_call({:connect, opts, conn_pid}, _from, state) do
58 - host = opts |> Keyword.fetch! :host
59 - port = opts |> Keyword.fetch! :port
58 + host = opts |> Keyword.fetch!(:host)
59 + port = opts |> Keyword.fetch!(:port)
60 60
61 - client_id = opts |> Keyword.fetch! :client_id
62 - username = opts |> Keyword.get :username, ""
63 - password = opts |> Keyword.get :password, ""
64 - will_topic = opts |> Keyword.get :will_topic, ""
65 - will_message = opts |> Keyword.get :will_message, ""
66 - will_qos = opts |> Keyword.get :will_qos, 0
67 - will_retain = opts |> Keyword.get :will_retain, 0
68 - clean_session = opts |> Keyword.get :clean_session, 1
69 - keep_alive = opts |> Keyword.get :keep_alive, 100
61 + client_id = opts |> Keyword.fetch!(:client_id)
62 + username = opts |> Keyword.get(:username, "")
63 + password = opts |> Keyword.get(:password, "")
64 + will_topic = opts |> Keyword.get(:will_topic, "")
65 + will_message = opts |> Keyword.get(:will_message, "")
66 + will_qos = opts |> Keyword.get(:will_qos, 0)
67 + will_retain = opts |> Keyword.get(:will_retain, 0)
68 + clean_session = opts |> Keyword.get(:clean_session, 1)
69 + keep_alive = opts |> Keyword.get(:keep_alive, 100)
70 70
71 71 message = Message.connect(client_id, username, password,
72 72 will_topic, will_message, will_qos,
  @@ -75,48 +75,48 @@ defmodule Hulaaki.Client do
75 75 state = Map.merge(%{connection: conn_pid}, state)
76 76
77 77 connect_opts = [host: host, port: port]
78 - :ok = state.connection |> Connection.connect message, connect_opts
78 + :ok = state.connection |> Connection.connect(message, connect_opts)
79 79 {:reply, :ok, state}
80 80 end
81 81
82 82 def handle_call({:publish, opts}, _from, state) do
83 - topic = opts |> Keyword.fetch! :topic
84 - msg = opts |> Keyword.fetch! :message
85 - dup = opts |> Keyword.fetch! :dup
86 - qos = opts |> Keyword.fetch! :qos
87 - retain = opts |> Keyword.fetch! :retain
83 + topic = opts |> Keyword.fetch!(:topic)
84 + msg = opts |> Keyword.fetch!(:message)
85 + dup = opts |> Keyword.fetch!(:dup)
86 + qos = opts |> Keyword.fetch!(:qos)
87 + retain = opts |> Keyword.fetch!(:retain)
88 88
89 89 message =
90 90 case qos do
91 91 0 ->
92 92 Message.publish(topic, msg, dup, qos, retain)
93 93 _ ->
94 - id = opts |> Keyword.fetch! :id
94 + id = opts |> Keyword.fetch!(:id)
95 95 Message.publish(id, topic, msg, dup, qos, retain)
96 96 end
97 97
98 - :ok = state.connection |> Connection.publish message
98 + :ok = state.connection |> Connection.publish(message)
99 99 {:reply, :ok, state}
100 100 end
101 101
102 102 def handle_call({:subscribe, opts}, _from, state) do
103 - id = opts |> Keyword.fetch! :id
104 - topics = opts |> Keyword.fetch! :topics
105 - qoses = opts |> Keyword.fetch! :qoses
103 + id = opts |> Keyword.fetch!(:id)
104 + topics = opts |> Keyword.fetch!(:topics)
105 + qoses = opts |> Keyword.fetch!(:qoses)
106 106
107 107 message = Message.subscribe(id, topics, qoses)
108 108
109 - :ok = state.connection |> Connection.subscribe message
109 + :ok = state.connection |> Connection.subscribe(message)
110 110 {:reply, :ok, state}
111 111 end
112 112
113 113 def handle_call({:unsubscribe, opts}, _from, state) do
114 - id = opts |> Keyword.fetch! :id
115 - topics = opts |> Keyword.fetch! :topics
114 + id = opts |> Keyword.fetch!(:id)
115 + topics = opts |> Keyword.fetch!(:topics)
116 116
117 117 message = Message.unsubscribe(id, topics)
118 118
119 - :ok = state.connection |> Connection.unsubscribe message
119 + :ok = state.connection |> Connection.unsubscribe(message)
120 120 {:reply, :ok, state}
121 121 end
122 122
  @@ -151,7 +151,7 @@ defmodule Hulaaki.Client do
151 151 case qos do
152 152 1 ->
153 153 message = Message.publish_ack message.id
154 - :ok = state.connection |> Connection.publish_ack message
154 + :ok = state.connection |> Connection.publish_ack(message)
155 155 _ ->
156 156 # unsure about supporting qos 2 yet
157 157 end
  @@ -168,7 +168,7 @@ defmodule Hulaaki.Client do
168 168 on_publish_receive [message: message, state: state]
169 169
170 170 message = Message.publish_release message.id
171 - :ok = state.connection |> Connection.publish_release message
171 + :ok = state.connection |> Connection.publish_release(message)
172 172
173 173 {:noreply, state}
174 174 end
  @@ -111,9 +111,11 @@ defmodule Hulaaki.Connection do
111 111 def handle_info({:tcp, socket, data}, state) do
112 112 :inet.setopts(socket, active: :once)
113 113 messages = decode_packets(data)
114 - messages |> Enum.each fn(message) ->
115 - Kernel.send state.client, {:received, message}
116 - end
114 + Enum.each(messages,
115 + fn(message) ->
116 + Kernel.send state.client, {:received, message}
117 + end
118 + )
117 119 {:noreply, state}
118 120 end
119 121
  @@ -137,9 +139,9 @@ defmodule Hulaaki.Connection do
137 139
138 140 defp open_tcp_socket(opts) do
139 141 timeout = 100
140 - host = opts |> Keyword.fetch! :host
142 + host = opts |> Keyword.fetch!(:host)
141 143 host = if is_binary(host), do: String.to_char_list(host), else: host
142 - port = opts |> Keyword.fetch! :port
144 + port = opts |> Keyword.fetch!(:port)
143 145 tcp_opts = [:binary, {:active, :once}, {:packet, :raw}]
144 146
145 147 {:ok, socket} = :gen_tcp.connect(host, port, tcp_opts, timeout)
  @@ -154,7 +156,7 @@ defmodule Hulaaki.Connection do
154 156 defp dispatch_message(socket, message) do
155 157 packet = Packet.encode(message)
156 158 :inet.setopts(socket, active: :once)
157 - socket |> :gen_tcp.send packet
159 + socket |> :gen_tcp.send(packet)
158 160 end
159 161
160 162 end
  @@ -1,13 +1,13 @@
1 1 defmodule Hulaaki.Mixfile do
2 2 use Mix.Project
3 3
4 - @version "0.0.2"
4 + @version "0.0.3"
5 5
6 6 def project do
7 7 [app: :hulaaki,
8 8 version: @version,
9 9 name: "Hulaaki",
10 - elixir: "~> 1.0",
10 + elixir: "~> 1.2",
11 11 source_url: "https://github.com/suvash/hulaaki",
12 12 homepage_url: "https://github.com/suvash/hulaaki",
13 13 deps: deps,
  @@ -25,11 +25,11 @@ defmodule Hulaaki.Mixfile do
25 25 end
26 26
27 27 defp deps do
28 - [{:inch_ex, "~> 0.2.4", only: :docs},
29 - {:earmark, "~> 0.1", only: [:dev, :docs]},
30 - {:ex_doc, "~> 0.7", only: [:dev, :docs]},
31 - {:dialyze, "~> 0.1.3", only: :test},
32 - {:excoveralls, "~> 0.3", only: [:dev, :test]}]
28 + [{:inch_ex, "~> 0.5.3", only: :docs},
29 + {:earmark, "~> 0.2.1", only: [:dev, :docs]},
30 + {:ex_doc, "~> 0.12", only: [:dev, :docs]},
31 + {:dialyze, "~> 0.2.1", only: :test},
32 + {:excoveralls, "~> 0.5.4", only: [:dev, :test]}]
33 33 end
34 34
35 35 defp description do
  @@ -39,14 +39,14 @@ defmodule Hulaaki.Mixfile do
39 39 end
40 40
41 41 defp package do
42 - [contributors: ["Suvash Thapaliya"],
42 + [maintainers: ["Suvash Thapaliya"],
43 + files: ["lib", "mix.exs", "README.md", "LICENSE.txt"],
43 44 licenses: ["MIT"],
44 - links: %{github: "https://github.com/suvash/hulaaki"}]
45 + links: %{Github: "https://github.com/suvash/hulaaki"}]
45 46 end
46 47
47 48 defp docs do
48 - {ref, 0} = System.cmd("git", ["rev-parse", "--verify", "--quiet", "HEAD"])
49 - [readme: "README.md", main: "README",
50 - source_ref: ref, source_url: "https://github.com/suvash/hulaaki"]
49 + [source_ref: "v#{@version}", main: "readme", readme: "readme.md",
50 + source_url: "https://github.com/suvash/hulaaki"]
51 51 end
52 52 end