sunscraper 1.1.0.beta3 → 1.2.0.beta1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. data/ext/common/common.pro +13 -0
  2. data/ext/common/libsunscraper_common.a +0 -0
  3. data/ext/common/sunscraperproxy.cpp +11 -0
  4. data/ext/{standalone → common}/sunscraperproxy.h +5 -5
  5. data/ext/{embed → common}/sunscraperwebpage.cpp +0 -0
  6. data/ext/{embed → common}/sunscraperwebpage.h +0 -0
  7. data/ext/common/sunscraperworker.cpp +124 -0
  8. data/ext/common/sunscraperworker.h +50 -0
  9. data/ext/embed/embed.pro +14 -12
  10. data/ext/embed/sunscraperexternal.cpp +17 -16
  11. data/ext/embed/sunscraperinterface.cpp +206 -0
  12. data/ext/embed/sunscraperinterface.h +66 -0
  13. data/ext/embed/sunscraperlibrary.cpp +2 -12
  14. data/ext/embed/sunscraperlibrary.h +0 -1
  15. data/ext/embed/sunscraperthread.cpp +49 -0
  16. data/ext/embed/sunscraperthread.h +24 -0
  17. data/ext/extconf.rb +5 -3
  18. data/ext/standalone/standalone.pro +12 -6
  19. data/ext/standalone/sunscrapermain.cpp +13 -3
  20. data/ext/standalone/sunscraperrpc.cpp +76 -88
  21. data/ext/standalone/sunscraperrpc.h +19 -22
  22. data/ext/standalone/sunscraperrpcserver.cpp +26 -0
  23. data/ext/standalone/sunscraperrpcserver.h +24 -0
  24. data/ext/sunscraper-ext.pro +1 -1
  25. data/lib/sunscraper.rb +14 -14
  26. data/lib/sunscraper/library.rb +9 -9
  27. data/lib/sunscraper/standalone.rb +53 -107
  28. data/spec/sunscraper_spec.rb +86 -44
  29. data/sunscraper.gemspec +1 -1
  30. metadata +19 -17
  31. data/ext/embed/sunscraper.cpp +0 -92
  32. data/ext/embed/sunscraper.h +0 -47
  33. data/ext/embed/sunscraperproxy.cpp +0 -14
  34. data/ext/embed/sunscraperproxy.h +0 -24
  35. data/ext/embed/sunscraperworker.cpp +0 -163
  36. data/ext/embed/sunscraperworker.h +0 -58
  37. data/ext/standalone/sunscraperproxy.cpp +0 -14
  38. data/ext/standalone/sunscraperworker.cpp +0 -60
  39. data/ext/standalone/sunscraperworker.h +0 -34
@@ -1,14 +0,0 @@
1
- #include <QWebPage>
2
- #include <QWebFrame>
3
- #include <QtDebug>
4
- #include "sunscraperproxy.h"
5
-
6
- SunscraperProxy::SunscraperProxy(QWebPage *parent, unsigned queryId) :
7
- QObject(parent), m_webPage(parent), m_queryId(queryId)
8
- {
9
- }
10
-
11
- void SunscraperProxy::finish()
12
- {
13
- emit finished(m_queryId, m_webPage->mainFrame()->toHtml());
14
- }
@@ -1,60 +0,0 @@
1
- #include <QApplication>
2
- #include <QWebPage>
3
- #include <QWebFrame>
4
- #include "sunscraperworker.h"
5
- #include "sunscraperproxy.h"
6
- #include <QtDebug>
7
-
8
- SunscraperWorker::SunscraperWorker(QObject *parent) :
9
- QObject(parent)
10
- {
11
- }
12
-
13
- void SunscraperWorker::loadHtml(unsigned queryId, QString html)
14
- {
15
- QWebPage *webPage = initializeWebPage(queryId);
16
- webPage->mainFrame()->setHtml(html);
17
- }
18
-
19
- void SunscraperWorker::loadUrl(unsigned queryId, QString url)
20
- {
21
- QWebPage *webPage = initializeWebPage(queryId);
22
- webPage->mainFrame()->load(url);
23
- }
24
-
25
- void SunscraperWorker::finalize(unsigned queryId)
26
- {
27
- Q_ASSERT(_webPages[queryId] != NULL);
28
-
29
- _webPages[queryId]->deleteLater();
30
- _webPages.remove(queryId);
31
- }
32
-
33
- QWebPage *SunscraperWorker::initializeWebPage(unsigned queryId)
34
- {
35
- Q_ASSERT(_webPages[queryId] == NULL);
36
-
37
- QWebPage *webPage = new QWebPage(this);
38
- webPage->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true);
39
-
40
- connect(webPage->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()),
41
- this, SLOT(attachAPI()));
42
-
43
- _webPages[queryId] = webPage;
44
-
45
- return webPage;
46
- }
47
-
48
- void SunscraperWorker::attachAPI()
49
- {
50
- QWebFrame *origin = static_cast<QWebFrame *>(QObject::sender());
51
- QWebPage *page = origin->page();
52
-
53
- unsigned queryId = _webPages.key(page, 0);
54
- Q_ASSERT(queryId != 0);
55
-
56
- SunscraperProxy *proxy = new SunscraperProxy(page, queryId);
57
- connect(proxy, SIGNAL(finished(uint,QString)), this, SIGNAL(finished(uint,QString)));
58
-
59
- origin->addToJavaScriptWindowObject("Sunscraper", proxy, QScriptEngine::QtOwnership);
60
- }
@@ -1,34 +0,0 @@
1
- #ifndef SUNSCRAPERWORKER_H
2
- #define SUNSCRAPERWORKER_H
3
-
4
- #include <QObject>
5
- #include <QMutex>
6
- #include <QMap>
7
-
8
- class QWebPage;
9
-
10
- class SunscraperWorker : public QObject
11
- {
12
- Q_OBJECT
13
-
14
- public:
15
- SunscraperWorker(QObject *parent = 0);
16
-
17
- signals:
18
- void finished(unsigned queryId, QString result);
19
-
20
- public slots:
21
- void loadHtml(unsigned queryId, QString html);
22
- void loadUrl(unsigned queryId, QString url);
23
- void finalize(unsigned queryId);
24
-
25
- private slots:
26
- void attachAPI();
27
-
28
- private:
29
- QMap<unsigned, QWebPage *> _webPages;
30
-
31
- QWebPage *initializeWebPage(unsigned queryId);
32
- };
33
-
34
- #endif // SUNSCRAPERWORKER_H