tweakphoeus 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03974c87632b69ec0956d0fb451350d8ffc5ec85
4
- data.tar.gz: 42f409a675c5344ce173cc44b6d8624d333498bd
3
+ metadata.gz: 25fcb7384bff257ed82f16287a2078fb1ab6df54
4
+ data.tar.gz: b6cf182064ac2b990da3eb9cb3b6349cb09133c0
5
5
  SHA512:
6
- metadata.gz: 78889b4ee6c703190e18d51996bb2b7bbf8d22a6667240283edc16b8a9f07dd0659c823d8e1910bbaff0f696300f2cb0c6510e64d334eca9db77f0efb27381f8
7
- data.tar.gz: f83067fb5b6234937144eb86518277ec45e6bab6afa235d4ada784aa2645d089d83ae7e1536274dc470f5e79277d94b7ed10fd5a66ec8c45f834696f8c07af47
6
+ metadata.gz: f9a15688c4bf67db44d22aa55c0ca36921763ea6e4ed1a7f4a7e30c2795c7468e6a2162b20a1c71dbfaa36e4c9b306a23aa19d00cd347b6c94eb0100c2d0f5fa
7
+ data.tar.gz: 3e291860a978a89b0835cf391e3c3dd4b1dfe4c1c2f5bad27a98895e76a7d18ce1a5621e0fb7d006824c7a854d57cd13c6b4eb4be7807586c026d696c37acbb7
data/CHANGELOG.md CHANGED
@@ -1,2 +1,3 @@
1
1
  -- v0.1.0 - First stable version: Typhoeus dependency version updated
2
2
  -- v0.2.0 - Refactor of cookies format
3
+ -- v0.2.1 - Add accessor for base headers and merge method
data/README.md CHANGED
@@ -5,9 +5,12 @@
5
5
  [![Issue Count](https://codeclimate.com/github/basestylo/Tweakphoeus/badges/issue_count.svg)](https://codeclimate.com/github/basestylo/Tweakphoeus)
6
6
  # Tweakphoeus
7
7
 
8
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tweakphoeus`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+ We usually describe this gem as 'typhoeus on steroids'. We add some browser features, for example cookies management and automation in tipical headers that browsers define in his HTTP stack.
9
+
10
+ We love scrapping and this gem was created for this.
11
+
12
+ From crazy developers to another crazy developers, Created in Bizneo.com and maintained in this small group of developers.
9
13
 
10
- TODO: Delete this and the text above, and describe your gem
11
14
 
12
15
  ## Installation
13
16
 
@@ -26,6 +29,10 @@ Or install it yourself as:
26
29
  $ gem install tweakphoeus
27
30
 
28
31
  ## Usage
32
+ Like Typhoeus
33
+
34
+ Tweakphoeus.get(url)
35
+ Tweakphoeus.get(url, headers: hash, body: hash)
29
36
 
30
37
  TODO: Write usage instructions here
31
38
 
@@ -1,3 +1,3 @@
1
1
  module Tweakphoeus
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/tweakphoeus.rb CHANGED
@@ -4,6 +4,7 @@ require "typhoeus"
4
4
  module Tweakphoeus
5
5
  class Client
6
6
  attr_accessor :cookie_jar
7
+ attr_accessor :base_headers
7
8
 
8
9
  def initialize()
9
10
  @cookie_jar = {}
@@ -12,7 +13,6 @@ module Tweakphoeus
12
13
  "User-Agent" => "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0",
13
14
  "Accept-Language" => "es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3",
14
15
  "Accept-Encoding" => "",
15
- "DNT" => "1",
16
16
  "Connection" => "keep-alive"
17
17
  }
18
18
  end
@@ -57,7 +57,7 @@ module Tweakphoeus
57
57
  private
58
58
 
59
59
  def http_request(url, body: nil, headers: nil, redirect: false, method: method)
60
- request_headers = @base_headers
60
+ request_headers = merge_default_headers(headers)
61
61
  request_headers["Cookie"] = inject_cookies(url, headers)
62
62
  request_headers["Referer"] = get_referer
63
63
  response = Typhoeus.send(method, url, body: body, headers: request_headers)
@@ -77,6 +77,10 @@ module Tweakphoeus
77
77
  response
78
78
  end
79
79
 
80
+ def merge_default_headers headers
81
+ headers ? @base_headers.merge(headers) : @base_headers
82
+ end
83
+
80
84
  def obtain_cookies response
81
85
  set_cookies_field = response.headers["Set-Cookie"]
82
86
  return if set_cookies_field.nil?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tweakphoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Martin Garcia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus