stw_engine 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,75 @@
1
+ # stw_engine gem
2
+
3
+ ## What is it?
4
+ A Ruby gem wrapping the shrinktheweb.com API.
5
+
6
+ ## Who should use it?
7
+ Any Ruby on Rails developer who wants/needs to generate screenshots from sites using shrinktheweb.com.
8
+
9
+
10
+ ## Installation
11
+
12
+ gem install nokogiri
13
+
14
+ gem install stw_gem
15
+
16
+
17
+
18
+
19
+ ### Configuration
20
+
21
+ You must define your Access key or secret key, they are required:
22
+
23
+ StwEngine.config({
24
+
25
+ # required
26
+ :api_key => 'xXXXXXXXXXXXXX',
27
+ :private_key => 'xxxx,
28
+
29
+ #optional use if supported
30
+ :size => 'lg',
31
+
32
+
33
+ })
34
+
35
+
36
+
37
+ ##### size
38
+ The following sizes are available depending on the account level
39
+
40
+
41
+ * v6 (default)
42
+ * v4
43
+ * v3
44
+
45
+
46
+
47
+
48
+ ##### mode
49
+
50
+
51
+ ## Usage
52
+
53
+
54
+ Generate an image tag:
55
+
56
+ stw_show url
57
+
58
+ Generate an image tag with size option:
59
+
60
+ stw_show url, :size => 'xlg'
61
+
62
+
63
+
64
+ To only get the image url:
65
+
66
+ stw_show_url url, [options]
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
@@ -12,9 +12,8 @@ module StwEngine
12
12
  self.api_secret = c[:api_secret]
13
13
 
14
14
  # optional
15
- self.mode = c[:mode] if c[:mode]
16
- self.api_version = c[:api_version] if c[:api_version]
17
- self.api_url = c[:api_url] if c[:api_url]
15
+ self.size = c[:size] if c[:size]
16
+
18
17
  end
19
18
 
20
19
  def api_key=api_key
@@ -34,6 +33,14 @@ module StwEngine
34
33
  raise 'StwEngine error: No api secret defined!' if @api_secret.nil?
35
34
  @api_secret
36
35
  end
36
+
37
+ def size=size
38
+ @size = size
39
+ end
40
+
41
+ def size
42
+ @size
43
+ end
37
44
 
38
45
  def mode=mode
39
46
  raise "StwEngine error: Invalid mode, only #{ MODES.join(', ') } are allowed" unless MODES.include?(mode.to_s)
@@ -51,14 +51,14 @@ module StwEngine
51
51
 
52
52
  end
53
53
 
54
- # function to store the image and return the image url
55
- def stw_show url, options ={}
56
- sizes = ['xlg', 'lg', 'sm', 'vsm', 'tny', 'mcr']
57
- params = {:stwaccesskeyid => StwEngine.api_key ,
58
- :stwu => StwEngine.api_secret}
59
-
60
- if options.key?(:size)
61
- case options[:size]
54
+ #function to return only url
55
+
56
+ def stw_show_url url, options={}
57
+ stw_show url, options, only_url=true
58
+ end
59
+
60
+ def add_size size, params
61
+ case size
62
62
  when 'xlg'
63
63
  params['stwxmax'] = 320
64
64
  when 'lg'
@@ -73,7 +73,24 @@ module StwEngine
73
73
  params['stwxmax'] = 75
74
74
 
75
75
  end
76
+ return params
77
+ end
78
+
79
+ # function to store the image and return the image url
80
+ def stw_show url, options ={}, only_url=false
81
+ sizes = ['xlg', 'lg', 'sm', 'vsm', 'tny', 'mcr']
82
+ params = {:stwaccesskeyid => StwEngine.api_key ,
83
+ :stwu => StwEngine.api_secret}
84
+
85
+ if StwEngine.size
86
+ params = add_size StwEngine.size, params
76
87
  end
88
+
89
+ if options.key?(:size)
90
+ params = add_size options[:size], params
91
+
92
+ end
93
+ #return params
77
94
  params[:stwurl] = url
78
95
 
79
96
 
@@ -129,6 +146,11 @@ module StwEngine
129
146
  open(path, 'wb') do |file|
130
147
  file << open(image).read
131
148
  end
149
+ img_path = "/stw/#{filename}"
150
+
151
+ if only_url
152
+ return img_path
153
+ end
132
154
 
133
155
  img = "<img src=\"/stw/#{filename}\"/>"
134
156
  img.respond_to?(:html_safe) ? img.html_safe : img
@@ -1,3 +1,3 @@
1
1
  module StwEngine
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stw_engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-10 00:00:00.000000000 Z
12
+ date: 2013-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sqlite3
16
- requirement: &83508830 !ruby/object:Gem::Requirement
16
+ requirement: &83705640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *83508830
24
+ version_requirements: *83705640
25
25
  description: Show thumbnail from shrinktheweb
26
26
  email:
27
27
  - sabirmostofa@gmail.com
@@ -33,6 +33,7 @@ files:
33
33
  - Gemfile
34
34
  - Gemfile.lock
35
35
  - MIT-LICENSE
36
+ - README.markdown
36
37
  - README.rdoc
37
38
  - Rakefile
38
39
  - app/assets/images/stw_engine/.gitkeep
@@ -70,6 +71,7 @@ files:
70
71
  - lib/tasks/stw_engine_tasks.rake
71
72
  - script/rails
72
73
  - stw_engine-0.0.1.gem
74
+ - stw_engine-0.0.2.gem
73
75
  - stw_engine.gemspec
74
76
  - test/dummy/README.rdoc
75
77
  - test/dummy/Rakefile