Skip to content

Commit

Permalink
Release V1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
saiqulhaq committed May 4, 2018
1 parent a541dff commit 4d45ea8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
51 changes: 44 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Or install it yourself as:

### Configure the HTTP client

```ruby
FirebaseDynamicLink.configure do |config|
# the adapter should be supported by Faraday
# more info look at https://github.com/lostisland/faraday/tree/master/test/adapters
Expand All @@ -39,17 +40,22 @@ Or install it yourself as:
# default 'UNGUESSABLE'
config.suffix_option = 'SHORT' or 'UNGUESSABLE'

# required
config.dynamic_link_domain = 'http://xyz.app.goo.gl'
# required, Don't put http://
config.dynamic_link_domain = 'xyz.app.goo.gl'

# default 3 seconds
config.timeout = 3

# default 3 seconds
config.open_timeout = 3
end
```

### Shorten a link

```ruby
client = FirebaseDynamicLink::Client.new
link = "http://domain.com/path/path"
options = {
# optional, to override default suffix default config
suffix_option: '',
Expand All @@ -66,11 +72,46 @@ Or install it yourself as:

# options argument is optional
result = client.shorten_link(link, options)
```

### Shorten parameters

```ruby
client = FirebaseDynamicLink::Client.new
options = {
# optional, to override default suffix default config
suffix_option: '',

# optional, to override default dynamic_link_domain default config
dynamic_link_domain: '',

# optional, timeout of each request of this instance
timeout: 10,

# optional, open timeout of each request of this instance
open_timeout: 10
}

parameters = {
link: link,
android_info: {
android_package_name: name,
}
ios_info: {},
navigation_info: {},
analytics_info: {},
social_meta_tag_info: {}
}

# options argument is optional
result = client.shorten_parameters(parameters, options)
```

if request successful, then the result should be like following hash object

or if the request reached daily quota, client will throw `FirebaseDynamicLink::QuotaExceeded` error

```ruby
{
:link=>"https://--.app.goo.gl/ukph",
:preview_link=>"https://--.app.goo.gl/ukph?d=1",
Expand All @@ -86,14 +127,10 @@ or if the request reached daily quota, client will throw `FirebaseDynamicLink::Q
}
]
}
```

otherwise it will throw `FirebaseDynamicLink::ConnectionError` error, with message = http error message

# NOTE

this gem only implemented to shorten long dynamic link til now, next version is supposed to
be able shorten a JSON object

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down
9 changes: 9 additions & 0 deletions lib/firebase_dynamic_link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,22 @@
module FirebaseDynamicLink
extend Dry::Configurable

# called when invalid configuration given
class InvalidConfig < StandardError; end

# called when HTTP request failed
class ConnectionError < StandardError; end

# called when Firebase says that no more quota
class QuotaExceeded < StandardError; end

# @!group Configuration
# @!method adapter
# @!scope class
# Selected Faraday HTTP adapter
# @!method adapter=(adapter_key)
# @!scope class
# Set Faraday HTTP adapter
# @param adapter_key [Symbol]
# @example
# FirebaseDynamicLink.adapter = :patron
Expand All @@ -29,8 +36,10 @@ class QuotaExceeded < StandardError; end

# @!method api_key
# @!scope class
# Given api key
# @!method api_key=(key)
# @!scope class
# Set api key
# @param key [String]
# @since 0.1.0
setting :api_key
Expand Down
1 change: 1 addition & 0 deletions lib/firebase_dynamic_link/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require "firebase_dynamic_link/link_renderer"

module FirebaseDynamicLink
# Main class that responsible to shorten link or parameters
class Client
extend Forwardable

Expand Down
5 changes: 5 additions & 0 deletions lib/firebase_dynamic_link/connection.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

module FirebaseDynamicLink
# Responsible to do HTTP request
class Connection
extend Forwardable

Expand All @@ -16,18 +17,22 @@ def initialize(end_point)
client.options.open_timeout = FirebaseDynamicLink.config.open_timeout
end

# @see Faraday.timeout=
def timeout=(time)
client.options.timeout = time
end

# @see Faraday.timeout
def timeout
client.options.timeout
end

# @see Faraday.open_timeout=
def open_timeout=(time)
client.options.open_timeout = time
end

# @see Faraday.open_timeout
def open_timeout
client.options.open_timeout
end
Expand Down

0 comments on commit 4d45ea8

Please sign in to comment.