phearb 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f06e119930b57be1783b3db3ae0b0a145e6980c9
4
+ data.tar.gz: 6a3bce7762ecd6aca90f9acf574e119425dd302d
5
+ SHA512:
6
+ metadata.gz: abf95b843c9e1eb1c327a861abc7f5f8fcdcc91291bece8c31682796ce555bd8b50c26c9b837e03c326ed5f87875a028bf7b3ebab4d7048f9611c7b3ab4821a4
7
+ data.tar.gz: 397a8230cfcd59bdb92791df3592d312b815fded5e469546891196194ecf4c184fe49da3841faed51e0690f58a45adfa907256674eedbc44efbeff9568bdb94e
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in phearb.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Phearb
2
+
3
+ Phearb is a library for handling connections to [**phear**](https://github.com/Tomtomgo/phearjs) servers. It allows ruby apps to easy fetch sites source code using phear.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'phearb'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install phearb
20
+
21
+ ## Configuration
22
+
23
+ Put these lines in the configuration section of you app. In rails you should probably add an `initializer` or in one of your `environment` files:
24
+
25
+ ```ruby
26
+ Phearb.configure do |config|
27
+ config.host = <host> # Defaults to 'localhost'
28
+ config.port = <port> # Defaults to 8100
29
+ end
30
+ ```
31
+
32
+ ## Usage
33
+ ```ruby
34
+ response = Phearb.fetch('http://www.google.com')
35
+ puts response.content if response.success
36
+ ```
37
+
38
+ Simply calling `Phearb.fetch(<url>)` will do the job. It returns an `Phearb::Response` object wrapping the phearb server response with one method per key:
39
+ ```
40
+ {
41
+ "success": true,
42
+ "input_url": "http://such-website.com",
43
+ "final_url": "http://www.such-website.com/",
44
+ "had_js_errors": false,
45
+ "content": "<html>rendered</html>",
46
+ "request_headers": {},
47
+ "response_headers": {
48
+ "date": "Sun, 08 Feb 2015 15:11:22 GMT",
49
+ "content-encoding": "gzip",
50
+ "cache-control": "max-age=60",
51
+ "content-type": "text/html; charset=utf-8"
52
+ }
53
+ }
54
+ ```
55
+
56
+ Then if you need access to the `final_url` you can call `response.final_url`.
57
+
58
+ ## Development
59
+
60
+ 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.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/joaquinrulin/phearb.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "phearb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ require 'rest_client'
2
+ require 'phearb/response'
3
+
4
+ module Phearb
5
+ class Agent
6
+
7
+ def initialize(url)
8
+ @url = url
9
+ end
10
+
11
+ def fetch
12
+ http_response = RestClient.get(server_url, params: { fetch_url: @url })
13
+ Response.from_json(http_response)
14
+ end
15
+
16
+ private
17
+
18
+ def server_url
19
+ "#{Phearb.configuration.host}:#{Phearb.configuration.port}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ module Phearb
2
+ class Configuration
3
+ attr_accessor :host
4
+ attr_accessor :port
5
+
6
+ DEFAULT_HOST = 'localhost'
7
+ DEFAULT_PORT = 8100
8
+
9
+ def initialize
10
+ @host = DEFAULT_HOST
11
+ @port = DEFAULT_PORT
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ require 'active_support/core_ext/object/blank'
2
+
3
+ module Phearb
4
+ class Response < OpenStruct
5
+
6
+ def self.from_json(json)
7
+ return nil if json.blank?
8
+ new(JSON.parse(json))
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Phearb
2
+ VERSION = "1.0.0"
3
+ end
data/lib/phearb.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'phearb/version'
2
+ require 'phearb/configuration'
3
+ require 'phearb/agent'
4
+
5
+ module Phearb
6
+ class << self
7
+ attr_accessor :configuration
8
+
9
+ def configuration
10
+ @configuration ||= Configuration.new
11
+ end
12
+
13
+ def configure
14
+ yield(configuration)
15
+ end
16
+
17
+ def fetch(url)
18
+ Agent.new(url).fetch
19
+ end
20
+ end
21
+ end
data/phearb.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'phearb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "phearb"
8
+ spec.version = Phearb::VERSION
9
+ spec.authors = ["Joaquín Moreira"]
10
+ spec.email = ["jmoreiras@gmail.com"]
11
+
12
+ spec.summary = %q{Simplified connection to phear servers}
13
+ spec.homepage = "https://github.com/joaquinrulin/phearb"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "webmock", "~> 2.0"
24
+ spec.add_development_dependency "byebug", "~> 9.0"
25
+
26
+ spec.add_runtime_dependency "activesupport", "~> 4.2"
27
+ spec.add_runtime_dependency "rest-client", "~> 1.8"
28
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phearb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Joaquín Moreira
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '9.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '9.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rest-client
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.8'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.8'
111
+ description:
112
+ email:
113
+ - jmoreiras@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - ".rspec"
120
+ - ".travis.yml"
121
+ - Gemfile
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/phearb.rb
127
+ - lib/phearb/agent.rb
128
+ - lib/phearb/configuration.rb
129
+ - lib/phearb/response.rb
130
+ - lib/phearb/version.rb
131
+ - phearb.gemspec
132
+ homepage: https://github.com/joaquinrulin/phearb
133
+ licenses: []
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.5.1
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Simplified connection to phear servers
155
+ test_files: []